Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC3 @Html.EditorForModel NullReferenceException
    primarykey
    data
    text
    <p>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.</p> <pre><code>// 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 { &lt;link href="@Url.Content("~/Content/MvcMembership.css")" rel="stylesheet" type="text/css" /&gt; } &lt;h2 class="someclass"&gt;Test Form&lt;/h2&gt; &lt;div class="otherclass"&gt; @using (Html.BeginForm("Test", "MyController")) { @Html.EditorForModel() &lt;input type="submit" value="Create" /&gt; @Html.ValidationSummary(true) } &lt;/div&gt; </code></pre> <p>I receive the following exception at @Html.EditorForModel() on the HttpGet in my actual code or in tests controllers/views. </p> <pre><code>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: </code></pre> <p>Any thoughts would be GREAT!!! -- Jeff</p> <p>[Edit] Few bullets:</p> <ul> <li> 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. </li> <li> I found a working example online while searching for solution: http://mvcmembership.codeplex.com/ </li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload