返回带有身份注册表单的修改模型

时间:2015-05-07 19:31:07

标签: c# asp.net-mvc razor

我使用默认表单注册具有Identity的用户,仅略微更改了HTML。

@using (Html.BeginForm("Register", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
                    {
                        @Html.AntiForgeryToken()
                        @Html.ValidationSummary("", new { @class = "text-danger" })

                        // Do something with something here

                        <div class="form-group">
                            @Html.LabelFor(m => m.Fornavn, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Fornavn, new { @class = "form-control", autocomplete = "off" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(m => m.Etternavn, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Etternavn, new { @class = "form-control", autocomplete = "off" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(m => m.Email, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.TextBoxFor(m => m.Email, new { @class = "form-control", autocomplete = "off" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(m => m.Password, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.PasswordFor(m => m.Password, new { @class = "form-control", autocomplete = "off" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(m => m.ConfirmPassword, new { @class = "col-md-2 control-label" })
                            <div class="col-md-10">
                                @Html.PasswordFor(m => m.ConfirmPassword, new { @class = "form-control", autocomplete = "off" })
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-offset-2 col-md-10">
                                <input type="submit" class="btn btn-primary" value="Registrer" />
                            </div>
                        </div>
                    }

它正在使用这个注册模型,我添加了一个新的道具,我刚刚调用了#34;东西&#34;。
如何设置&#34;的某些内容&#34;在我看来,当提交表单时,我可以访问我的&#34;某些东西&#34;在控制器?

非常感谢你

public class RegisterViewModel
{
    public bool something { get; set; }

    [Required]
    [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 2)]
    [Display(Name = "Fornavn")]
    public string Fornavn { get; set; }

    [Required]
    [StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 2)]
    [Display(Name = "Etternavn")]
    public string Etternavn { get; set; }

    [Required]
    [EmailAddress]
    [Display(Name = "Email")]
    public string Email { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Passord")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Gjenta passord")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

1 个答案:

答案 0 :(得分:1)

如果您在控制器中设置了值,则可以使用HiddenFor()输入扩展名为表单添加隐藏字段:

@Html.HiddenFor(m => m.something)

或者如果您只想对值进行硬编码。你可以使用:

@Html.Hidden("something", true)
相关问题