I'm just doing a little above and beyond debugging, having turned on some addition exception blocking in my project. I'm seeing an exception I've never dealt with before though:
<div class="form-group">
@Html.LabelFor(model => model.shift_type, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("shift_type", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.shift_type, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.shift_notes, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.shift_notes, new {maxlength = 100})<-- Failing Here -->
@Html.ValidationMessageFor(model => model.shift_notes, "", new { @class = "text-danger" })
</div>
</div>
The exception message says it's being thrown on the lambda. Everything else on the page uses the same data model, and works fine. So I'm curious what could be the problem. When I paste the exception into notepad++, I get this:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
And here's the model, with the field intact.
I think the problem is the second attribute is an anonymous object without a collection initializer. Razor is unable to figure out which overload method you are trying to use. Try:
@Html.TextBoxFor(model => model.shift_notes, htmlAttributes: new {maxlength = 100})
User contributions licensed under CC BY-SA 3.0