我一直无法让默认编辑器模板在我的 MVC 4 Razor Web 应用程序中工作。我一直找不到任何线索。我想覆盖字符串、密码等。我已经在我的模型中尝试过 UIHints(即使你不应该使用默认编辑器模板),确保我在我的视图中使用 EditorFor 并将编辑器模板放在 ~ /视图/共享/编辑器模板。我被困住了。任何帮助,将不胜感激。谢谢!
public class LoginModel
{
[Required(AllowEmptyStrings = false)]
[StringLength(128)]
[Display(Name = "User name")]
public string UserName { get; set; }
[Required(AllowEmptyStrings = false)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Display(Name = "Remember me?")]
public bool RememberMe { get; set; }
[HiddenInput()]
public Guid UserEmailAddressId { get; set; }
[HiddenInput()]
public bool IsVerified { get; set; }
}
我绑定到我的模型的部分视图......
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>RegisterModel</legend>
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.PrimaryEmailAddress)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PrimaryEmailAddress)
@Html.ValidationMessageFor(model => model.PrimaryEmailAddress)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Password)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Password)
@Html.ValidationMessageFor(model => model.Password)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ConfirmPassword)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ConfirmPassword)
@Html.ValidationMessageFor(model => model.ConfirmPassword)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.CultureId)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.CultureId, (IEnumerable<SelectListItem>)ViewBag.Cultures, " -- Select -- ", null)
@Html.ValidationMessageFor(model => model.CultureId)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.TimeZoneId)
</div>
<div class="editor-field">
@Html.DropDownListFor(model => model.TimeZoneId, (IEnumerable<SelectListItem>)ViewBag.TimeZones, " -- Select -- ", null)
@Html.ValidationMessageFor(model => model.TimeZoneId)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
在 ~/Views/Shared/EditorTemplates/Password.cshtml 下的 Password.cshtml 文件中
@Html.Password("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "k-textbox" })
THE EDITOR IS WORKING