1
在我進入細節,這是我驗證總結工作,但個別驗證消息不工作
環境:VS 2008的ASP.NET MVC 2
基本型號代碼
[DisplayName("Current Application Status")]
[Required(ErrorMessage = "Current Status has to be provided")]
public virtual int CurrStatus{ get; set; }
腳本引用
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
<link href="../../Content/jqueryui.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.9.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.10.3.custom.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.validate.unobtrusive.js" type="text/javascript"></script>
查看代碼
<tr>
<td><%= Html.LabelFor(model => model.CurrStatus) %></td>
<td>
<%= Html.DropDownListFor(model => model.CurrStatus, Model.CurrentStatus, "-- Select Current Status --").ToString().Replace("CurrStatus", "Application.CurrStatus")%>
<%=Html.ValidationMessageFor(model=>model.CurrStatus) %>
</td>
</tr>
控制器代碼
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Prefix = "Application")] Application model)
{
try
{
if (ModelState.IsValid)
{
//save to db
}
else
{
InitSelectListItems();
model.CurrentStatus = CurrentStatusModel.GetModelInstance().GetAllAsSelectListItems();
return View(model);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
在視圖中,驗證摘要顯示與所提交的模型錯誤列表。但是由於某些原因,單個錯誤消息未顯示。最重要的是,在將條目添加到web.config中並將jQUery腳本添加到腳本文件夾後,我啓用了客戶端驗證。客戶端驗證也沒有被觸發。任何幫助,將不勝感激。
我試着將ValidationSummary添加到true。它隱藏了顯示的錯誤摘要,但它也沒有顯示模型級錯誤。我不確定我瞭解驗證摘要助手。我沒有用於驗證摘要的自定義擴展。我已經包含了所有的JQuery腳本標籤。我在原始文章中使用了jQuery部分。 – vikramjb
這是我得到的最接近的答案,所以我接受它。感謝您的時間。 – vikramjb