问题
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