2

From the action stand of point, how can I differentiate an ajax request from a regular one.

puclic class GroupController : Controller
{
     public ActionResult AddGroup()
     {
        if(//regular request...)
           return view()
        else //an ajax call
          return Partial("GroupPartialView)
     }
} 

The idea is that If a user is being added to a group that doesn't exist, the group can be added using a dialog without leaving the the Manage user pages.

Thanks for helping.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
Richard77
  • 20,343
  • 46
  • 150
  • 252

1 Answers1

7

You could use the IsAjaxRequest() extension method:

if(Request.IsAjaxRequest())
{
    // it's an AJAX request
    return PartialView("GroupPartialView);
}
else
{
    // it was normal request
    return View();
}
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • thank you, but initially i was using `jquery 1.11.0` and thus `Request.IsAjaxRequest()` always returning false, when looked at chrome developer console i got this error : `live is not a function` in `jquery.unobtrusive-ajax.js` as said [here](http://stackoverflow.com/a/22180196/2218697) i used `jquery 1.7.0`, now it works fine. But how to handle multiple jquery versions in same `_Layout` ? because i need both `jquery 1.11.0 and 1.7.0`. – Shaiju T Jan 12 '16 at 14:24