无法看到验证摘要

时间:2013-07-30 11:20:04

标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-4 razor

我有一个要求,比如我需要在页面顶部显示验证摘要,因为我在我的视图中已经这样做了

@model MvcSampleApplication.Models.CrossFieldValidation
@{
    ViewBag.Title = "Index";
}    
<h2>Index</h2>
@Html.ValidationSummary(true) // here I have mentioned that validation summary true
 but its not showing all messages in bulleted list 
@using (Html.BeginForm("PostValues", "CrossFieldsTxtboxes"))
{          
    <div class ="editor-field">
      @Html.TextBoxFor(m => m.TxtCrossField)
       @Html.ValidationMessageFor(m=>m.TxtCrossField)
    </div>
   <div class =".editor-field">
       @Html.DropDownListFor(m=> m.SelectedValue , Model.Items)
       @Html.ValidationMessageFor(m=>m.SelectedValue)
   </div>
    <div class ="editor-field">
      @Html.TextBoxFor(m =>m.ShippingValue)
      @Html.ValidationMessageFor(m=>m.ShippingValue) 
    </div>
    <div class =".editor-field">
       @Html.DropDownListFor(m=> m.SelectedShippingItemValue , Model.Items)
       @Html.ValidationMessageFor(m=>m.SelectedShippingItemValue)
   </div>
    <div class ="editor-field">
      @Html.TextBoxFor(m =>m.DeliverPrice)
       @Html.ValidationMessageFor(m=>m.DeliverPrice)
    </div>
    <div class =".editor-field">
       @Html.DropDownListFor(m=> m.SelectedDeliveredItem , Model.Items)
       @Html.ValidationMessageFor(m=>m.SelectedDeliveredItem)
   </div>       
    <div class=".editor-field">
          <input id="PostValues" type="Submit" value="PostValues" />
        </div>
}

目前我能够在下拉列表和文本框附近显示错误消息但我想在页面顶部为此目的在我的视图中需要做哪些更改 任何人都会建议任何想法.. 非常感谢...

注意:我正在使用剃刀视图引擎..

2 个答案:

答案 0 :(得分:1)

将以下代码添加到web.config。它会起作用

<appSettings>
  <add key="ClientValidationEnabled" value="true" />
  <add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>

更新了

 @Html.ValidationSummary(false)     

答案 1 :(得分:1)

只需尝试放置所有@Html.ValidationMessageFor(m=>m.Items)

正下方

@Html.ValidationSummary(true)

并将此代码放在页面上的所需位置。