I wanted to have a hyperlink which when clicked opens in same page without the complete page being refreshed instead of opening different link. In my controller I have following function
public ActionResult PrivacyPolicy()
{
if (Request.IsAjaxRequest())
{
return PartialView();
}
return View();
}
when i run the the program and insert a break point at return view();
I realise that my program always returns view()
instead of PartialView();
here is the index.cshtml
code
@section head{
<script type="text/javascript"
src="@Url.Content("~/scripts/AjaxDemo.js")"></script>
}
@Html.ActionLink("Show the Privacy Policy", "PrivacyPolicy", null, new{id="privacyLink"})
<div id="privacy"></div>
in the partial view PrivacyPolicy I just have few texts.
and the AjaxDemo.js
looks like this
$(document).ready(function () {
$('#privacyLink').click(function (event) {
event.preventDefault();
var url = $(this).attr('href');
$('#privacy').load(url);
});
});
why doesn't my program return partial view? or why is it not taking the ajax request? Shouldn't my program open the link in same index page(CustomAjax), if the javascript in my browser is enables?