1
首先,对不起我的英语不好。如何通过ajax.BeginForm更改内容?
我想当一个人点击按钮“Page1”,控制器返回“Page1”的renderpartial和“page2”和“allPage”的相同的东西。
我的看法是:
@{
ViewBag.Title = "Title";
}
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<h2>Title</h2>
@using (Ajax.BeginForm("NameAction", //controller action name
"NameController", //controller name
new AjaxOptions //ajax options that tell mvc how to perform the replacement
{
UpdateTargetId = "ViewPage", //id of div to update
HttpMethod = "Post" //how to call the controller action
}, new { id = "FormName" }))
{
<input type="submit" id="btn" value="p1" id="p1"/>
<input type="submit" id="btn" value="p2" id="p2"/>
<input type="submit" id="btn" value="AllPage" id="AllPage"/>
<div id="ViewPage">
//render partial view
</div>
}
我的控制器:
public class NameController : Controller
{
[HttpPost]
public ActionResult NameAction(String btn)
{
if (Request.IsAjaxRequest())
if(btn="p1")
return PartialView("p1");
if(btn="2")
return PartialView("p2");
if(btn="3")
return PartialView("p3");
return View();
}
}
Request.isAjaxRequest总是等于false和partialview不更新的股利,但删除所有页面
感谢你的帮助。
MVC2或MVC3?请清理你问题的标签。 – ThiefMaster 2012-03-13 16:32:00
@ThiefMaster,我已经移除了'asp.net-mvc-2'标签,它不能与'razor'一起使用。 – 2012-03-13 16:36:58
对不起,感谢您对Darin Dimitrov的更正。这是工作中,因为,与我的“字符串btn”的解决方案不是空的,但ajax选项不起作用:(如果我在我的控制器测试isAjaxRequest等于永远为false。partialview擦除我的所有页面,而不是更新div:s – Zoners 2012-03-13 16:54:55