jquery - Ajax.IsAjaxRequest() always returns false? -


in controller class code "if(request.isajaxrequest())" returns false... can me figure out? if use ajax.beginform in cshtml page , not use jquery file returns true.

this cshtml file

<form method="get" action="@url.action("index")" data-otf-ajax="true" data-otf-target="#listofdata"> <input type="search" name="searchterm"/> <input type="submit" value="search"/> 

this controller logic:

 public actionresult index( string searchterm)     {         var departments = db.departments.include(d => d.administrator);         if(request.isajaxrequest())         {              if (searchterm != null)             {                  var departments2 = db.departments.where(x => x.name.contains(searchterm));                  return partialview("_department", departments2.tolist());                           }         }         return view(departments.tolist());     } 

and jquery file handle ajax request

$(function () { var ajaxformsubmit = function () {     var form = $(this);     var options = {         url: $form.attr("action"),         type: $form.attr("method"),         data: $form.serialize()      };     $.ajax(options).done(function (data) {         var $target = $($form.attr("data-otf-target"));         $target.replacewith(data);     });     return false; };  $("form[data-otf-ajax='true']").submit(ajaxformsubmit); }); 

use jquery.unobtrusive-ajax.min.js solve problem


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -