Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I distinguish between requests made from RenderAction and via AJAX?

In ASP.NET MVC, there is a useful method Request.IsAjaxRequest that I can use to determine whether the request is made via AJAX. However, RenderAction method seems to be calling the controller/action via AJAX as well.

I would like the calls via RenderAction to return a View, whereas calls via AJAX to return a Json object. Is there any way I can distinguish calls from those two sources?

EDIT: Re. jim: I simply call a RenderAction within a View:

In SomeView.ascx:

Html.RenderAction("Action", "AnotherController", new { id = "some ID" });
like image 414
William Niu Avatar asked Jul 11 '11 12:07

William Niu


1 Answers

I believe you could use ControllerContext.IsChildAction to determine if a method was called by RenderAction().

like image 180
mrydengren Avatar answered Oct 29 '22 15:10

mrydengren