开发者

Is current action a ChildAction?

开发者 https://www.devze.com 2023-02-09 05:40 出处:网络
How can I determine if current action is a ChildAction or routed main action? Should I check the URL and compare to the action\'s name? That\'s not so nice, since it\'s dependent on routing patterns..

How can I determine if current action is a ChildAction or routed main action? Should I check the URL and compare to the action's name? That's not so nice, since it's dependent on routing patterns...

Or should I make 开发者_Python百科two actions of the same name, put a ChildActionOnly on one of them and have separate logic (mainly returning View() or PartialView())? How will the overloads be differentiated?

Okay, from an other perspective: How to make it so, that if it's a ChildAction then return a PartialView, otherwise a full View?


You could use the IsChildAction property:

public ActionResult Index()
{
    if (ControllerContext.IsChildAction)
    {
         // The Index action was invoked as child action using 
         // @Html.Action("index")
    }
    ...
}
0

精彩评论

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