I'm seeing and odd exception and completely out of ideas on how to resolve this. I'm sure I'm overlooking something very obvious. I had the following view work but did something and now cannot figure out why it suddenly stopped.
// All in an Area
// Controller
public ViewResult Test()
{
return View();
}
[HttpPost]
public ViewResult Test(TestModel testModel)
{
// Do some work
// Redirect or
return View(testModel);
}
// Model
public class TestModel
{
[Required]
public string Name { get; set; }
}
// View
@model MyApp.Areas.Admin.Models.TestModel
@{
ViewBag.Title = "Create New User";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section HeadSection {
<link href="@Url.Content("~/Content/MvcMembership.css")" rel="stylesheet" type="text/css" />
}
<h2 class="someclass">Test Form</h2>
<div class="otherclass">
@using (Html.BeginForm("Test", "MyController"))
{
@Html.EditorForModel()
<input type="submit" value="Create" />
@Html.ValidationSummary(true)
}
</div>
I receive the following exception at @Html.EditorForModel() on the HttpGet in my actual code or in tests controllers/views.
System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=App_Web_field.master.5f132152.av8tutrk
StackTrace:
at ASP.views_inputbuilders_editortemplates_field_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in http://server/Views/InputBuilders/EditorTemplates/Field.Master:line 5
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
InnerException:
Any thoughts would be GREAT!!! -- Jeff
[Edit] Few bullets:
- I have a working solution/project with test code. The major difference is project size. This is a big project with lots of areas, controllers, models and views. So routing, references, etc... are different. I have even stepped through and confirmed Model is null and with what little reading I can find it appears EditorFor[Model] uses reflections to create fields so it is something else.
- I found a working example online while searching for solution: http://mvcmembership.codeplex.com/
TestModelas the model? b: what editor is it using? a default one? a custom one? what?