I have an Area like below.
Below are the Controller actions.
[HttpGet]
public ActionResult Index_partial()
{
return PartialView("_PartialPage1");
}
[HttpGet]
public ActionResult Index()
{
AdminModule model = new AdminModule();
model.MyName = "My Name";
return View("Index", model);
}
View
@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>
===================================
Partial View
@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" />
}
=====================================
In the View, I have a button, on clicking it should render the Partial View in
<p id="pid"></p>
Issue is - on clicking the button is navigating the page to Partial View, It should instead render the Partial View Html in p tag. How to do this ?