我有一个像下面这样的区域。
以下是控制器操作。
[HttpGet]
public ActionResult Index_partial()
{
return PartialView("_PartialPage1");
}
[HttpGet]
public ActionResult Index()
{
AdminModule model = new AdminModule();
model.MyName = "My Name";
return View("Index", model);
}
看法
@model _1.Areas.Admin.Models.AdminModule
@{
ViewBag.Title = "Index";
Layout = "~/Areas/Admin/Views/Shared/_LayoutPage1.cshtml";
}
<h2>
Index</h2>
<script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript">
</script>
<script type="text/javascript" src="/scripts/jquery.unobtrusive-ajax.js">
</script>
<div id="myForm">
@using (Html.BeginForm())
{
<p id="pid">
</p>
<input onclick="ClickHere();" type="submit" value="Button" />
}
<script language="javascript" type="text/javascript">
function ClickHere() {
debugger;
var url = '@Url.Action("Index_partial", "Admin")';
$('#p').load("@Url.Action("Index_partial", "Admin")");
}
</script>
</div>
====================================
局部视图
@model _1.Areas.Admin.Models.AdminModule
@using (Ajax.BeginForm("Index", "Admin",
new AjaxOptions { UpdateTargetId = "myForm", HttpMethod = "Post" }))
{
@Html.LabelFor(i => i.MyName)
@Html.TextBoxFor(i => i.MyName)
@Html.ValidationMessageFor(i => i.MyName)
<p id="getDateTimeString">
</p>
<input type="submit" value="Click here" id="btn" />
}
======================================
在视图中,我有一个按钮,单击它应该呈现部分视图
<p id="pid"></p>
问题是 - 单击按钮将页面导航到部分视图,它应该在 p 标记中呈现部分视图 Html。这该怎么做 ?