[英]validation summary in mvc 4.0
I am new to mvc I am trying simple validation summary but the validation summary is not showing in UI.IS there any syntax wrong. 我是mvc的新手,正在尝试简单的验证摘要,但该验证摘要未显示在UI.IS中,语法有误。
@{Html.ValidationSummary();}
@{Html.BeginForm();}
<p>
Name:-@Html.TextBox("Name")
</p>
<p>
Age:-@Html.TextBox("Age")
</p>
<input type="submit" value="Sign In" />
<h6>SignIn</h6>
@{Html.EndForm();}
This should work: 这应该工作:
@using (Html.BeginForm("YourActionName", "YourControllerName","Upload", FormMethod.Post)) {
@Html.ValidationSummary(false);
<p>
Name: @Html.TextBoxFor(m => m.Name)
</p>
<p>
Age: @Html.TextBoxFor(m => m.Age)
</p>
<input type="submit" value="Sign In" />
<h6>SignIn</h6>
}
...Assuming that you have validation attributes (eg [Required]
) on the properties on the model. ...假设您在模型的属性上具有验证属性(例如
[Required]
)。
Notice that the validation summary is inside the Html.BeginForm()
block. 请注意,验证摘要位于
Html.BeginForm()
块内。
Also notice the TextboxFor
syntax (rather than Textbox
) which makes sure that your properties are strongly typed. 还要注意
TextboxFor
语法(而不是Textbox
),该语法可确保您的属性被严格键入。
Also, make sure you have these settings in the appsettings section of your web.config file: 另外,请确保在web.config文件的appsettings部分中具有以下设置:
<add key="ClientValidationEnabled" value="true"></add>
<add key="UnobtrusiveJavaScriptEnabled" value="true"></add>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.