[英]Multiple Ajax.BeginForm on page
我需要實現多個Ajax表單。
HTML
@using (Ajax.BeginForm("PerformAction", "Home", new AjaxOptions { OnSuccess = "OnSuccess", OnFailure = "OnFailure" }))
{
<h3>This is a demo form #1.</h3>
@Html.LabelFor(model => model.FirstName)
@Html.TextBoxFor(model => model.FirstName, null, new { @class = "labelItem" })
<input type="submit" value="Submit" />
}
<br />
<br />
@using (Ajax.BeginForm("PerformAction2", "Home", new AjaxOptions { OnSuccess = "OnSuccess2", OnFailure = "OnFailure2" }))
{
<h3>This is a demo form #2. </h3>
@Html.LabelFor(model => model.FirstName)
@Html.TextBoxFor(model => model.FirstName, null, new { @class = "labelItem" })
<input type="submit" value="Submit" />
}
<br />
<br />
<script type="text/javascript">
function OnSuccess(response) {
alert(response);
}
function OnFailure2(response) {
alert("222 Whoops! That didn't go so well did it?");
}
function OnSuccess2(response) {
alert(response);
}
function OnFailure(response) {
alert("Whoops! That didn't go so well did it?");
}
</script>
C#
[AcceptVerbs("POST")]
public ActionResult PerformAction(FormCollection formCollection, Person model)
{
model.FirstName += " Form 1";
return View(model);
}
[AcceptVerbs("POST")]
public ActionResult PerformAction2(FormCollection formCollection, Person model)
{
model.FirstName += " Form 2";
return View(model);
}
但我面臨的錯誤是ASP .NET MVC 4正在尋找某種局部形式。
我不想使用任何部分表單,只需要使用JavaScript OnSuccess
和OnSuccess2
有什么猜測怎么辦?
使用View()
或PartialView()
,MVC將嘗試查找名稱等於操作名稱的視圖。
所以,只是不要返回一個View(model)
返回一個EmptyResult()
或一個JSON對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.