62,074
社区成员
发帖
与我相关
我的任务
分享
[AllowAnonymous]
public ActionResult Index()
{
ViewBag.SubPage = "a";
return View();
}
[AllowAnonymous]
[HttpPost]
public ActionResult Index(string subPage)
{
ViewBag.SubPage = subPage;
return View();
}
[AllowAnonymous]
[HttpPost]
public ActionResult Index2(string subPage)
{
return PartialView(subPage);
}
Index页面如下:
<div>
<span>整页更新</span>
<button onclick ="getNewPage('a');">A页面</button>
<button onclick ="getNewPage('b');">B页面</button>
<form id="formTest" method="post" style="display:none">
<input id="subPage" name="subPage" type="hidden" />
</form>
</div>
<div>
<span>部分更新</span>
<button onclick ="updatePage('a');">A页面</button>
<button onclick ="updatePage('b');">B页面</button>
</div>
<div id = "c" style="border:solid 1px black">
@Html.Partial((string)ViewBag.SubPage)
</div>
<script type="text/javascript">
function getNewPage(subPage) {
$("#subPage").val(subPage);
$("#formTest").submit();
}
function updatePage(subPage) {
$.ajax({
type: "POST",
async: true,
data: { subPage: subPage },
url: "@UrlHelper.GenerateContentUrl("~/home/index2",Context)",
success: function (data) {
$("#c").html(data);
},
error: function (data, status, e) {
alert("更新内容时发生错误。\n" + data.status);
}
});
}
</script>
部分页a:
这是视图A
部分面b:
这是视图B