I have an ASP.NET MVC 3 application with 2 areas which are seperate projects referenced from the main application. Both the area projects sit with the Areas directory of the main application. I was wondering if i can call DisplayTemplates from one area in another.
For example i have added the following template in the ~/Areas/Area1/Views/Shared/DisplayTemplates/Test.cshtml file:
@model string
Test Display Template
Now within a view in the Area2 project i say:
@Html.Display("Test", "~/Areas/Area1/Views/Shared/DisplayTemplates/Test.cshtml")
But it doesn’t display anything. I was wondering if someone could let me know if this is possible and what i am doing wrong.
Thanks
If you would like to share templates across Areas, place the template in the root View directory.
Instead of;
Place it here;
Also, the second argument of your Display helper method call;
Should be this;
As the second argument is your template name.
The MVC view engine will track down the template on name, not directory. This is a cleaner approach.