获取针对电流控制器 [英] Get current controller in view
问题描述
我有一个查看 - _Edit
这住在新闻M / V / C
我重用 V / M
通过 CategoryController
为:
返回PartialView(/查看/新闻/ _Edit.cshtml模型);
如何从视图中 - _Edit
我可以提醒控制器名称
当我:
警报('@ ViewContext RouteData.Values [控制器]的ToString()。');
值是:新闻
然而,网址为: /分类/ foobar的
有没有一种方法来获取值类别
提醒?谢谢
我已经把这个在我的部分观点:
@ HttpContext.Current.Request.RequestContext.RouteData.Values [控制器]。的ToString()
在同一种情况你描述,它显示,而不是局部视图的实际位置在URL中所描述的控制器(类别为你,为产品我)。
所以用这个来代替警报:
<$p$p><$c$c>alert('@HttpContext.Current.Request.RequestContext.RouteData.Values[\"controller\"].ToString()');I have a View - _Edit
which lives in News M/V/C
.
I reuse the V/M
via the CategoryController
as:
return PartialView("/Views/News/_Edit.cshtml", model);
How from within the View - _Edit
can I alert the controller name?
When I:
alert('@ViewContext. RouteData.Values["controller"].ToString()');
The Value is: News
However, the URL is: /Category/foobar
Is there a way to get the value 'Category'
to alert? thanks
I have put this in my partial view:
@HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString()
in the same kind of situation you describe, and it shows the controller described in the URL (Category for you, Product for me), instead of the actual location of the partial view.
So use this alert instead:
alert('@HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString()');
这篇关于获取针对电流控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!