2
我想弄清楚如何在用戶提交一個具有其UpdateTargetID
屬性集的Ajax窗體後顯示驗證錯誤。ASP.NET MVC:如何使用指定的UpdateTargetID驗證Ajax表單?
我很困難如何更新帶有驗證錯誤的Ajax表單而不將Create
PartialView返回到results
div。如果表單有效,那麼它應該返回部分視圖Records
。
Create.ascx
<% Using Ajax.BeginForm("Create",
"Record",
New Record With {.UserID = Model.UserID},
New AjaxOptions With {
.UpdateTargetId = "results",
.LoadingElementId = "loader"
})%>
Date Located
<%= Html.TextBoxFor(Function(model) model.DateLocated)%>
<%= Html.ValidationMessageFor(Function(model) model.DateLocated) %>
Description
<%= Html.TextBoxFor(Function(model) model.Description)%>
<%= Html.ValidationMessageFor(Function(model) model.Description) %>
<input id="btnSave" type="submit" value="Create" />
<span id="loader" class="loader">Saving...</span>
<%End Using%>
Records.ascx
<div id="results">
...
</div>
RecordController.vb
Function Create(ByVal newRecord As Record) As ActionResult
ValidateRecord(newRecord)
If Not ModelState.IsValid Then
Return PartialView("Create", newRecord)
End If
_repository.Add(newRecord)
_repository.Save()
Dim user = _repository.GetUser(newRecord.UserID)
Return PartialView("Records", user)
End Function
你可以在這裏介紹一下:http://stackoverflow.com/q/6040534/114029 – 2011-05-18 06:47:02