I’m using an Editor Template, the syntax in the view looks like this:
Html.EditorFor(m => m.Email)
The string editor template looks like this:
@{
var o = ViewData.ModelMetadata;
}
@model string
@Html.TextBox(o.PropertyName,
this.Model,
new { @class="textinput-single-line", placeholder = o.Watermark })
The problem is that upon postback, model.Email is null no matter what I type in the TextBox. Why is the text box value not properly bound to the model?
Edit: Here’s the HTML output
<fieldset>
<legend>Log in Form</legend>
<ol>
<li>
<div class="editor-for">
<label class="label-single-line" for="Email_Email">Email</label>
<input class="textinput-single-line" id="Email_Email" name="Email.Email" placeholder="" type="text" value=""/>
<div class="clearboth"/>
</div>
</li>
<li>
<div class="editor-for">
<span class="label-single-line"/>
<input class="tickbox-single-line" id="RememberMe_RememberMe" name="RememberMe.RememberMe" type="checkbox" value="true"/>
<input name="RememberMe.RememberMe" type="hidden" value="false"/>
<label class="label-tickbox" for="RememberMe_RememberMe">Remember me?</label>
<div class="clearboth"/>
</div>
</li>
</ol>
<input type="submit" value="Log in"/>
</fieldset>
Use
String.Emptyor""in your editor template. The view engine will figure out the correct name for you.