MVC 4.0中的验证摘要 [英] validation summary in mvc 4.0
本文介绍了MVC 4.0中的验证摘要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是mvc的新手,我正在尝试简单的验证摘要,但验证摘要未显示在UI中.IS语法有误.
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.
@{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();}
推荐答案
这应该有效:
@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>
}
...假设您在模型的属性上具有验证属性(例如[Required]
).
...Assuming that you have validation attributes (e.g. [Required]
) on the properties on the model.
请注意,验证摘要位于
Notice that the validation summary is inside the Html.BeginForm()
block.
还要注意TextboxFor
语法(而不是Textbox
),该语法可确保您的属性是强类型的.
Also notice the TextboxFor
syntax (rather than Textbox
) which makes sure that your properties are strongly typed.
此外,请确保在web.config文件的appsettings部分中具有以下设置:
Also, make sure you have these settings in the appsettings section of your web.config file:
<add key="ClientValidationEnabled" value="true"></add>
<add key="UnobtrusiveJavaScriptEnabled" value="true"></add>
这篇关于MVC 4.0中的验证摘要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文