asp.net mvc - why if(Request.IsAjaxRequest) is false -


i wanted have hyperlink when clicked opens in same page without complete page being refreshed instead of opening different link. in controller have following function

public actionresult privacypolicy() {     if (request.isajaxrequest())     {        return partialview();     }        return view(); } 

when run the program , insert break point @ return view(); realise program returns view() instead of partialview();

here index.cshtml code

@section head{      <script type="text/javascript"             src="@url.content("~/scripts/ajaxdemo.js")"></script> } @html.actionlink("show privacy policy", "privacypolicy", null, new{id="privacylink"})  <div id="privacy"></div> 

in partial view privacypolicy have few texts.

and ajaxdemo.js looks this

$(document).ready(function () {     $('#privacylink').click(function (event) {         event.preventdefault();         var url = $(this).attr('href');         $('#privacy').load(url);     }); }); 

why doesn't program return partial view? or why not taking ajax request? shouldn't program open link in same index page(customajax), if javascript in browser enables?

iirc event reserved word. try this:

$('#privacylink').click(function (e) {     e.preventdefault();     var url = $(this).attr('href');     $('#privacy').load(url); }); 

or:

$('#privacylink').click(function () {     var url = $(this).attr('href');     $('#privacy').load(url);     return false; }); 

also don't forget include jquery.js before ajaxdemo.js script.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -