If I remove the <umbraco:Macro Alias="MappingUmbraco" runat="server"></umbraco:Macro> then the page renders correctly (but obviously the WUC isn't run).
Thanks for the info, I was using @Umbraco.RenderMacro("MappingUmbraco") but the postbacks weren't working so I decided to try it with <umbraco:Macro Alias="MappingUmbraco" runat="server"></umbraco:Macro>.
I thought even if you were using MVC, you could still use WUCs?
Web User Controls in uLocalGovMVC
I have a Web User Control that works perfectly outside of Umbraco.
Having put it in UserControls and trying to display it, using
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
Layout = "ulgSections.cshtml";
}
@section MetaData {
}
<div class="row">
<div class="col-lg-12">
<div class="jumbotron">
<h2>@Umbraco.Field("sectionName") Section</h2>
@Umbraco.Field("bodyText")
<form id="form1" runat="server">
<umbraco:Macro Alias="MappingUmbraco" runat="server"></umbraco:Macro>
</form>
</div>
</div>
</div>
@*rewrite as partial view*@
@Umbraco.RenderMacro("ulg.landingpage")
@section Footer {
}
@section Scripts {
}
while the code it generates is there, the page instead of rendering correctly isn't pulling in the templates and is instead showing
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage @{ Layout = "ulgSections.cshtml"; } @section MetaData { }
etc etc
If I remove the <umbraco:Macro Alias="MappingUmbraco" runat="server"></umbraco:Macro> then the page renders correctly (but obviously the WUC isn't run).
Has anyone got any idea where I'm going wrong?
Thanks
You can't render a UserControl inside an MVC project because it's webforms. Look here for an alternative: http://stackoverflow.com/questions/12714071/user-control-equivelnt-in-asp-net-mvc-4
Jeroen
Hi i suspect its a mismatch between the kit being mvc and your user control being .net form based ?
depending on what your doing it might work, but you should add the macro to the page using the MVC syntax
@Umbraco.RenderMacro("MappingUmbraco")
this will call the macro correctly as part of the MVC render - but if the control is .net it will probibly still not work?
Kevin
It might work partially, but things like postbacks won't work.
Jeroen
Thanks for the info, I was using @Umbraco.RenderMacro("MappingUmbraco") but the postbacks weren't working so I decided to try it with <umbraco:Macro Alias="MappingUmbraco" runat="server"></umbraco:Macro>.
I thought even if you were using MVC, you could still use WUCs?
UserControls with postbacks only work if you're in webforms and you have a <form runat="server"> on your page.
There is a hybrid solution where some pages are masterpages and others are views, but I think that only works if the default project is webforms: http://umbraco.com/follow-us/blog-archive/2012/11/2/umbraco-4100-release-candidate.aspx
Jeroen
I'll have a look at that, thanks again.
I know when I did the Level 2 course, we converted a webform to mvc but I want to go the other way (apart from the lack of mvc to convert of course!).
Sorry, but the other way is a lot harder because webforms requires things like <form runat="server"> and a viewstate which you don't have in MVC.
Jeroen
is working on a reply...