How to consume ASP.NET (Razor) User Control OR MVC User Control in Layout Page? [duplicate]
Possible Duplicate开发者_运维技巧:
MVC 3: Add usercontrol to Razor view
It's simple to create both user control from the two world : ASP.NET+Razor or MVC 3.0.
But i do not known how to consume the user control FROM the razor "_layout.chtml" page.
I want to put such thing within the layout page:
<uc:MyTag Prop1="" Prop2="" />
So i need to declare this directive at top of the layout file :
<%@ Register TagPrefix="uc" TagName="MyTag" Src="Controls/Mytag.ascx" %>
BUT it does not work, help please !!!! It seems that <% is not allowed in razor "_layout.chtml" page.
Thank you
You can add a shared view like this
Html.RenderPartial("Mytag", model);
If my assumption is correct, that you are attempting to consume a Web Forms usercontrol in MVC using the Razor view engine (two seperate entities), then I would take a look at doing something like this.
精彩评论