是最新的行动ChildAction? [英] Is current action a ChildAction?

查看:102
本文介绍了是最新的行动ChildAction?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能确定目前的动作是ChildAction或路由主要的行动?我要查询的网址,并比较了动作的名字?这不是那么好,因为它依赖于路由模式......结果
或者我应该做同一个名字的两个动作,把ChildActionOnly在其中一人,并有独立的逻辑(主要是返回查看()或PartialView())?如何将重载有所区别?

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 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?

好吧,从其他角度看:怎样使它所以,如果它是一个ChildAction然后返回一个PartialView,否则一个完整的视图

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

推荐答案

您可以使用<$c$c>IsChildAction属性:

You could use the IsChildAction property:

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

这篇关于是最新的行动ChildAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆