2

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

Community
  • 1
  • 1
user645904
  • 61
  • 1
  • 3
  • Your title is confusing. Are you attempting to consume a Web Forms user control in a MVC3 application using Razor? – Jim D'Angelo Nov 20 '11 at 18:49
  • This question has been asked/answered [here](http://stackoverflow.com/questions/6317317/mvc-3-add-usercontrol-to-razor-view) – Tim Hobbs May 25 '12 at 05:26

2 Answers2

1

You can add a shared view like this

Html.RenderPartial("Mytag", model);
Kimtho6
  • 6,154
  • 9
  • 40
  • 56
  • Thank you but Html.RenderPartial does not exist in ASP.NET+Razor and it does not work under MVC 3 because MVC does not find the right extension method to call. – user645904 Mar 05 '11 at 12:46
  • It works for me in razor @Html.Partial("RoundCornersBottom") – Kimtho6 Mar 05 '11 at 12:59
  • Maybe, i badly created my user control, the file named "MyTag.ascx" is created under Views/Shared/MyTag.ascx. it contains 2 lines: (1) <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> (2) Hello from my user control – user645904 Mar 05 '11 at 13:12
  • Hmm i dont know if it works for ascx file but it works for schtml – Kimtho6 Mar 05 '11 at 13:26
0

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.

Jim D'Angelo
  • 3,952
  • 3
  • 25
  • 39