Executing an action on a controller in another area in .net

旧巷老猫 提交于 2019-12-24 20:39:51

问题


So I need to call an action on another controller in another area in .net

Reason being I have some conditional logic to determine whether or not to display something and that is common to my website and mobile version.

So in my mobile site(in a separate area called mobile) I would like to be able to do something like

@Html.Action("GetVideoHtml","Service",null)

Where Service is a controller in my default area and GetVideoHtml is the action, however again, I am in the mobile area. I could copy and paste the action into a local action but that seems silly

Thanks in advance


回答1:


Specifying area = "" in the route values does the trick:

@Html.Action("GetVideoHtml", "Service", new { area = "" })



回答2:


Would anyone like to clarify why this is the case above?

ALSO: This does NOT seem to work if the area is inside another folder IE: ~/shared/Templates/UserTemplates/View_Called You either must link to it directly or move it into a general folder, which might not be ideal



来源:https://stackoverflow.com/questions/11695658/executing-an-action-on-a-controller-in-another-area-in-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!