Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine if Call to Action is from a View

Is there a way to determine if a call to a controllers action is from a view using the Html.RenderAction function.

This is similar to Request.IsAjaxRequest. If the call comes from a view I would like to just render a partial view rather than the the full view with master page.

BTW Render partial is not a viable solution as the action fetches additional data

like image 927
Marty Trenouth Avatar asked Jan 06 '11 00:01

Marty Trenouth


1 Answers

Using the ControllerContext.IsChildAction has the given effect. this way I can provide the same HTML using a child action and a ajax request (for fallback on non javascript users)

        if (Request.IsAjaxRequest() || ControllerContext.IsChildAction)
            return PartialView("ViewName", results);
like image 174
Marty Trenouth Avatar answered Sep 28 '22 05:09

Marty Trenouth