2

MVC 4RazorWebアプリケーションでデフォルトのエディターテンプレートを機能させることができませんでした。手がかりが見つかりませんでした。文字列、パスワードなどをオーバーライドしたい。モデルでUIHintsを試しました(デフォルトのエディターテンプレートでは必要ありませんが)。ビューでEditorForを使用していることを確認し、エディターテンプレートを〜の下に配置しました。 / Views / Shared/EditorTemplates。私は立ち往生しています。どんな助けでもいただければ幸いです。ありがとう!

    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
4

1 に答える 1

1

私は間違ったビューを見ていました。実際のビューは@Html.TextBoxForを使用していたため、パスワードのデフォルトのエディターテンプレートはレンダリングされませんでした。デフォルトのエディターテンプレートを呼び出すには、@Html.EditorForを使用する必要があります。

于 2012-12-05T15:05:18.287 に答える