Copied to clipboard

Flag this post as spam?

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


  • Terry Clancy 204 posts 944 karma points
    Feb 17, 2016 @ 08:14
    Terry Clancy
    0

    Errors applying a "Layout" to an Umbraco MVC View

    Hi all,

    I am trying to apply a "Layout" to an MVC View called from an Umbraco Surface Controller. But when I add the following to be beginning of the file:

    @{
    Layout = "TTMaster.cshtml";
    }
    

    I get the following exception error:

        The model item passed into the dictionary is of type 'MyProject.Models.TT_ViewProfile.ViewProfileViewModel', 
    but this dictionary requires a model item of 
    type 'Umbraco.Web.Models.RenderModel'.
    

    My Controller calls the view with this:

            return View("ViewProfile", viewProfileViewModel);
    

    and below is the source for the View. Any help would be appreciated.

    Terry Clancy

    ClanceZ

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ViewProfileViewModel>
    
    @{
        Layout = "TTMaster.cshtml";
    }
    
    
    @using TeraTastic.Models.TT_ViewProfile
    <div class="container">
        <!-- Example row of columns -->
        <div class="row">
            <div class="col-md-12">
                @*style="background-color:aquamarine">*@
                <h3>TeraTastic Profile</h3>
            </div>
        </div>
    
    
        <h2>View Profile</h2>
        <div class="row">
            <div class="col-md-9">
                <h3>Email: @Model.Email</h3>
                <h3>Description: @Model.description</h3>
    
                <h3>LinkedIn: @Model.linkedIn</h3>
                <h3>Skype: @Model.skype</h3>
                <h3>Twitter: @Model.twitter</h3>
                <h3>Member ID: @Model.MemberID</h3>
                <h3>No Of Logins: @Model.numberOfLogins</h3>
                <h3>No of profile views: @Model.numberOfProfileViews</h3>
                <h3>Last Login Date: @Model.lastLoginDate</h3>
            </div>
            <div class="col-md-3">
                @*<!--<img src="@(Model.EmailAddress.GetGravatarUrl(250, string.Empty))" alt="@Model.Name" class="img-circle"/>-->*@
            </div>
        </div>
    
    </div>
    
  • Terry Clancy 204 posts 944 karma points
    Feb 17, 2016 @ 21:01
    Terry Clancy
    0

    I still have a problem with this, but here is some more information:

    Note that this page uses a custom route.

    Also, when I remove the following from my Layout Page (and move the Layout Page into my Views folder) the page works:

    inherits Umbraco.Web.Mvc.UmbracoTemplatePage

    it seems that this is conflicting with the following in my View page:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage

    However removing "inherits Umbraco.Web.Mvc.UmbracoTemplatePage" from my master Layout page will break the Umbraco pages and I want to have one Layout Template page for my whole site (both Umbraco Pages and pages with custom route pages) is that possible ?

    Thanks again

    Terry Clancy

    ClanceZ

  • Damien (Slipoch) 62 posts 346 karma points
    Sep 27, 2016 @ 06:00
    Damien (Slipoch)
    0

    +1 here

  • Damien (Slipoch) 62 posts 346 karma points
    Sep 28, 2016 @ 01:02
    Damien (Slipoch)
    0

    Two ways I understand to get around this problem

    Either make an Umbrcao Template and use the method:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<[your model here]>
    

    Or from your controller use TempData["mod"] = [your model variable] example below

    MyProject.Models.TT_ViewProfile.ViewProfileViewModel model1 = new MyProject.Models.TT_ViewProfile.ViewProfileViewModel();
    TempData["Mod"] = model1;
    

    then in the page you can unpack it:

    MyProject.Models.TT_ViewProfile.ViewProfileViewModel model1 = TempData["Mod"];
    
  • 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