开发者

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

开发者 https://www.devze.com 2023-03-19 03:50 出处:网络
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

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 call开发者_如何学Pythons 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" });


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

0

精彩评论

暂无评论...
验证码 换一张
取 消