Upon publishing my MVC 3 Web Application to my website I get an error stating an Object reference not set to an instance of an object.
The 'error' line is:
Line 2: ViewBag.Title = "Index";
This is my Index view:
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
This is my Home Controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace WebApplication.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
}
}
I have uploaded DLL's:
System.Web.Helpers
System.Web.Mvc
System.Web.Razor
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
Thanks for any assistance
I hit the same ViewBag error. in my case Model was null but the exception was directing to viewbag row.
When I passed a model to view error fixed.
When you look in /Views/Shared/_Layout.cshtml, you will probably see something like this:
<title>@ViewBag.Title</title>
It is assuming this property has been set somewhere. Usually, you set this in your child views. So the easiest solution is to modify your Index.cshtml view so that it resembles something like this:
@{
ViewBag.Title = "Title of the page";
Layout = "~/Views/Shared/_Layout.cshtml";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With