[英]Multiple Ajax.BeginForm on page
I need to implement multiple Ajax forms. 我需要实现多个Ajax表单。
html 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# 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);
}
But I am facing the error about that ASP .NET MVC 4 is looking for some kind of partial form. 但我面临的错误是ASP .NET MVC 4正在寻找某种局部形式。
I don't want to use any partial form and just I need to get working JavaScript OnSuccess
and OnSuccess2
我不想使用任何部分表单,只需要使用JavaScript
OnSuccess
和OnSuccess2
Any guess how it could be done? 有什么猜测怎么办?
Using View()
or PartialView()
, MVC it will try to find a view with a name equals to the action name. 使用
View()
或PartialView()
,MVC将尝试查找名称等于操作名称的视图。
So, just don't return a View(model)
Return a EmptyResult()
or a JSON object. 所以,只是不要返回一个
View(model)
返回一个EmptyResult()
或一个JSON对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.