Copied to clipboard

Flag this post as spam?

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


  • burgi 16 posts 98 karma points
    Nov 10, 2017 @ 13:09
    burgi
    0

    Refactoring a template

    I have a masterpage which is generating markup in the codebehind file.

    I want to refactor this so that the majority of the markup is in the masterpage rather than codebehind. My research suggests I need to use Razor but I'm not familiar enough with C# to implement this.

    Can anyone make any recommendations? Here is an example of my code:

    void mapOutput(List<StockistListItem> stockists, System.Web.UI.HtmlControls.HtmlGenericControl list, int resultlimit = 5)
    {
        for (int i = 0; i < resultlimit; i++)
        {
            list.InnerHtml += "<div id='item-" + stockists[i].Id + "' class='list'><div class='details'>";
            list.InnerHtml += "<span class='name'>" + stockists[i].CompanyName + "</span>";
            list.InnerHtml += "<ul>";
            list.InnerHtml += "<li>" + stockists[i].Postcode + "</li>";
            list.InnerHtml += "</ul>";
            list.InnerHtml += "</div></div>";
        }
    }
    

    And this is the mark up in the masterpage:

    <div id="list" runat="server" class="lists col-lg-3 col-md-3 col-sm-12 col-xs-12 mCustomScrollbar"></div>
    

    Any advice is greatly appreciated!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Nov 10, 2017 @ 13:55
    Dave Woestenborghs
    0

    Hi Burgi,

    What version of Umbraco are using ? MVC master templates have been supported since v6 and are the recommended way to go. In future versions (V8?) webforms are not going to be supported anymore. But I could be wrong about that.

    Dave

  • burgi 16 posts 98 karma points
    Nov 10, 2017 @ 14:18
    burgi
    0

    Hi Dave

    We are using 6.2.2, it is an inherited site which needs a lot of remedial work doing to it.

    Burgi

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Nov 10, 2017 @ 14:41
    Dave Woestenborghs
    0

    Hi Burgi,

    You can have MVC templates and web forms views side by side.

    Here is a guide on how to migrate from webforms to mvc in umbraco : https://umbraco.com/blog/moving-from-webforms-to-mvc/

    Here you can find some more info on how have them side by side : https://our.umbraco.org/forum/templating/templates-and-document-types/41492-Mixing-Web-Forms-and-Razor-Templates-in-the-same-Umbraco-instance

    dave

  • 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