Asp.net mvc 未拾取MVC必需属性

Asp.net mvc 未拾取MVC必需属性,asp.net-mvc,razor,attributes,html-helper,Asp.net Mvc,Razor,Attributes,Html Helper,在我的模型中,我的属性具有[Required]属性 [Required] public string Surname { get; set; } 在我看来,我有ValidationMessageFor()html助手 <div class="form-group"> @Html.LabelFor(model => model.Surname, htmlAttributes: new { @class = "control-label col-md-2" })

在我的模型中,我的属性具有
[Required]
属性

[Required]
public string Surname { get; set; }
在我看来,我有
ValidationMessageFor()
html助手

<div class="form-group">
    @Html.LabelFor(model => model.Surname, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.Surname, new { htmlAttributes = new { @class = "form-control" } })
        @Html.ValidationMessageFor(model => model.Surname, "", new { @class = "text-danger" })
    </div>
</div>

@LabelFor(model=>model.姓氏,htmlAttributes:new{@class=“controllabel col-md-2”})
@Html.EditorFor(model=>model.namname,new{htmlAttributes=new{@class=“form control”}})
@Html.ValidationMessageFor(model=>model.namname,“,new{@class=“text danger”})
然而,它并没有说当我去提交时该字段是必需的。我做错了什么?

您应该添加“Jquery.Validate”来验证输入数据。
但如果您没有自定义错误消息,则输入标记的required属性会更简单。

您应该在模型中添加错误消息,如下所示:

[Required(ErrorMessage = "Please Enter Name")]
public string Surname { get; set; }

您是否包含了相关脚本(
jquery
jquery.validate
jquery.validate.unobtrusive
)?谢谢,这与jquery验证一起解决了问题!:)