I've got an ASP.Net MVC 4, .net 4.5 project with bundling. when I add [Authorize] to my Controller, the @Scripts.Render and @Styles.Render calls are breaking with 'Object reference not set to an instance of an object.'
I can't for the life of me work out why!!
Has anyone come across this before? can anyone help?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project.Models;
using Project.Repositories;
namespace Project.Controllers
{
[Authorize]
public class HomeController : Controller
this breaks my _Layout view :
@model PageModel
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Project</title>
<meta name="description" content="">
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0'/><meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="format-detection" content="telephone=no">
@Styles.Render("~/Content/bootstrap")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/initializr")
Right, after scratching my head for hours on this and looking in all sorts of unrelated places, I've worked out the issue...
my _Layout view had some other razor calls that were looking at the pagemodel properties lower down, however when I get redirected to login for authentication, the pagemodel is null and that's what the issue was.
just remember folks, the line Visual Studio is breaking on isn't always the line with the actual issue, especially in razor, should have remembered this sooner!! look lower down, at the next statement.