我正在使用编辑器模板,视图中的语法如下所示:
Html.EditorFor(m => m.Email)
字符串编辑器模板如下所示:
@{
var o = ViewData.ModelMetadata;
}
@model string
@Html.TextBox(o.PropertyName,
this.Model,
new { @class="textinput-single-line", placeholder = o.Watermark })
问题是,在回发时,无论我在 TextBox 中输入什么内容,model.Email 都是空的。为什么文本框值没有正确绑定到模型?
编辑:这是 HTML 输出
<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>