Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve Wilkinson 128 posts 187 karma points
    Jan 07, 2014 @ 12:33
    Steve Wilkinson
    0

    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

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 07, 2014 @ 12:44
    Jeroen Breuer
    0

    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

  • Kevin Jump 1867 posts 11859 karma points MVP 4x c-trib
    Jan 07, 2014 @ 12:46
    Kevin Jump
    0

    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


  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 07, 2014 @ 12:53
    Jeroen Breuer
    0

    It might work partially, but things like postbacks won't work.

    Jeroen

  • Steve Wilkinson 128 posts 187 karma points
    Jan 07, 2014 @ 13:03
    Steve Wilkinson
    0

    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?

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 07, 2014 @ 13:06
    Jeroen Breuer
    0

    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

  • Steve Wilkinson 128 posts 187 karma points
    Jan 07, 2014 @ 13:27
    Steve Wilkinson
    0

    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!).

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Jan 07, 2014 @ 13:29
    Jeroen Breuer
    0

    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

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies