Copied to clipboard

Flag this post as spam?

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


  • Fredrik Blomberg 6 posts 76 karma points
    Oct 23, 2015 @ 08:58
    Fredrik Blomberg
    0

    Can`t preview a copied document type with content

    Can´t preview a copied document type I´m trying to copy an existing document type to later on modify it with some new specifications. I have made a copy of both the document type and a copied templet connected. When I try to preview a new content I get following error message. Can someone help med to figure out what the problem might be?

    Error message:

    Server Error in '/' Application.
    
    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'company.Web.Models.Article'. 
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
     Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'company.Web.Models.Article'.
    
    Source Error: 
    
    
     An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
    
    Stack Trace: 
    
    
    
    [InvalidOperationException: The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'company.Web.Models.Article'.]
       System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +589919
       System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +371
       System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +48
       Umbraco.Web.Mvc.UmbracoViewPage`1.SetViewData(ViewDataDictionary viewData) +726
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +98
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +115
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +93
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +294
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.<>c__DisplayClass1a.

    My templates:

    @using company.Web.Models
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<company.Web.Models.Article>
    @{
       Layout = "Master.cshtml";
    }
    <div class="main-info page text-center">
        @if (!string.IsNullOrEmpty(Model.TopImage))
       {
            <img src="@company.Library.Util.GetResizedImageUrl(Model.TopImage, 1900, 0, true, 235)" alt="@Model.Heading" title="@Model.Heading" />
       }
    </div>
    <div class="container">
        <div class="row page">
            @* Same condition as (1) below, but inversed *@
            @if (!((Model.SubMenuLevel3 != null && Model.SubMenuLevel3.Count > 0) || (Model.ArticlePuffs != null && Model.ArticlePuffs.Count() > 0)))
            {
                //Article start tag for pages without aside column
                @:<article class="col-sm-8 col-md-offset-2 col-md-8">
            }
            else
            {
                //Article start tag for pages with aside column
                @:<article class="col-sm-8 col-md-offset-2 col-md-7">
            }
                <h1>@Model.Heading</h1>
                @if(!string.IsNullOrEmpty(Model.Preamble))
                {
                    <p class="lead">@Model.Preamble</p>
                }
                @Html.Raw(Model.ContentBody)
            </article>
            @* Condition (1), see note above. (This condition is an OR-combination from the conditions inside the aside tag) *@
            @if ((Model.SubMenuLevel3 != null && Model.SubMenuLevel3.Count > 0) || (Model.ArticlePuffs != null && Model.ArticlePuffs.Count() > 0))
            {
                @:<aside class="col-sm-4 col-md-3">
            }
                @* Remember to update commented conditions above, if this changes *@
                @if (Model.SubMenuLevel3 != null && Model.SubMenuLevel3.Count > 0)
                {
                    <div class="top_line"></div>
                    <h3>
                        <a href="@Model.SubMenuLevel3.First().Ancestor().Url">@Model.SubMenuLevel3.First().Ancestor().Name</a>
                    </h3>
                    <nav class="navbar navbar-default">
                        <ul class="nav nav-stacked">
                            @foreach (IPublishedContent subPage in Model.SubMenuLevel3)
                            {
                                <li class="@(Util.IsChildSelected(subPage) ? "active" : "")">
                                    <a href="@subPage.Url">@subPage.Name</a>
                                </li>
                            }
                        </ul>
                    </nav>
                }
                @* Remember to update commented conditions above, if this changes *@
                @if (Model.ArticlePuffs != null && Model.ArticlePuffs.Count() > 0)
                {
                    foreach (IPublishedContent pc in Model.ArticlePuffs)
                    {
                        string puffType = pc.GetPropertyValue("puffType").ToString().ToLower();
                        string heading = pc.GetPropertyValue<string>("heading", string.Empty);
                        string mainBody = pc.GetPropertyValue<string>("content", string.Empty);
                        int linkId = pc.GetPropertyValue<int>("link", 0);
                        string quote = pc.GetPropertyValue<string>("quote", string.Empty);
                        string author = pc.GetPropertyValue<string>("author", string.Empty);
    
                        if (puffType == "puff" || puffType == "simple puff")
                        {
                            <div class="top_line"></div>
                            <h3>
                                @heading
                            </h3>
                            <p>@Util.CleanFromHtmlTags(mainBody)</p>
                            if (linkId > 0)
                            {
                                IPublishedContent content = Umbraco.Content(linkId);
                                if (content != null && !string.IsNullOrEmpty(content.Url))
                                {
                                    <p><a href="@content.Url">@Util.GetDictionaryValue("ReadMore")</a></p>
                                }
                            }
                        }
                        else if (puffType == "quote")
                        {
                            <blockquote>
                                <div class="blockquote">
                                    “@quote”
                                </div>
                                <div class="author">
                                    @author
                                </div>
                            </blockquote>
                        }
                        else if (puffType == "with round image")
                        {
                            <div class="top_line"></div>
                            <div class="round-image">
                                @if (pc.HasProperty("image"))
                                {
                                    IPublishedContent media = Umbraco.TypedMedia(pc.GetPropertyValue<int>("image"));
    
                                    if (media != null)
                                    {
                                        <img src="/[email protected]&width=217" alt="@pc.Name" title="@pc.Name" />
                                    }
                                }
                            </div>
                            <h2>@heading</h2>
                            <p>@Util.CleanFromHtmlTags(mainBody)</p>
                            if (linkId > 0)
                            {
                                IPublishedContent content = Umbraco.Content(linkId);
                                if (content != null && !string.IsNullOrEmpty(content.Url))
                                {
                                    <a href="@content.Url">
                                        @Util.GetDictionaryValue("ReadMore")
                                    </a>
                                }
                            }
                        }
                        else if (puffType == "with image")
                        {
                            <div class="top_line"></div>
                            <div class="logo">
                                <div>
                                    @if (pc.HasProperty("image"))
                                {
                                    IPublishedContent media = Umbraco.TypedMedia(pc.GetPropertyValue<int>("image"));
    
                                    if (media != null)
                                    {
                                        <img src="/[email protected]&width=217" alt="@pc.Name" title="@pc.Name" />
                                    }
                                }
                                </div>
                            </div>
                            @Html.Raw(mainBody)
                            if (linkId > 0)
                            {
                                IPublishedContent content = Umbraco.Content(linkId);
                                if (content != null && !string.IsNullOrEmpty(content.Url))
                                {
                                    <a href="@content.Url">
                                        @Util.GetDictionaryValue("ReadMore")
                                    </a>
                                }
                            }
                        }
                    }
                }
            @if ((Model.SubMenuLevel3 != null && Model.SubMenuLevel3.Count > 0) || (Model.ArticlePuffs != null))
            {
                @:</aside>
            }
        </div>
    </div>
    
  • Patrick Hansen 13 posts 83 karma points
    Oct 23, 2015 @ 14:47
    Patrick Hansen
    0

    Hey Fredrik

    What's the alias of your new Document Type?

    Can you link the controller used?

  • Fredrik Blomberg 6 posts 76 karma points
    Oct 24, 2015 @ 08:25
    Fredrik Blomberg
    0

    The new document type is "Artikel nya"

    I´m new with Umbraco.

    Mabey this is a stupid question but where do I link the controller?

  • Patrick Hansen 13 posts 83 karma points
    Oct 26, 2015 @ 11:48
    Patrick Hansen
    0

    Document types consists of an Alias and a Name. They are both listed under "Settings". Your Document type Alias is most likely ArtikelNya.

    Have you set up the project your self?

    Are you using one of the starter packs?

    And do you know if you are route hijacking?

    It sounds like your template is not getting the correct ViewModel from the Controller

  • Fredrik Blomberg 6 posts 76 karma points
    Oct 26, 2015 @ 12:06
    Fredrik Blomberg
    0

    Hello and thanks for answer!

    The alias is: ArtikelNya

    There was a Company before that did put up everything from the beginning.

    Now when they are not in the picture I try to figure out how to manage the homepage in future.

    How do I control if the homepage is route hijacking?

  • Patrick Hansen 13 posts 83 karma points
    Oct 26, 2015 @ 12:31
    Patrick Hansen
    0

    Do you have access to the code it self and not just Umbraco backoffice?

    You are trying to inherit the ViewModel of:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<company.Web.Models.Article>
    

    Which means you need a controller that passes on that ViewModel to the template you are using.

    You said you copied another Document Type and Template, let's say its Alias was "Artikel" then you might have a controller named "ArtikelController" in your project, which tries to pass on the correct ViewModel (In this case 'Article').

  • Fredrik Blomberg 6 posts 76 karma points
    Oct 26, 2015 @ 12:51
    Fredrik Blomberg
    0

    I have access to the homepage with Visual studio but are not very familiar how to use it.

  • Patrick Hansen 13 posts 83 karma points
    Oct 26, 2015 @ 13:16
    Patrick Hansen
    0

    I would advice you to read a bit about MVC, and look at the Controller in the project that matches the Alias you copied the Document type from.

    There's also some about route hijacking here: https://our.umbraco.org/documentation/reference/routing/custom-controllers

  • Fredrik Blomberg 6 posts 76 karma points
    Oct 26, 2015 @ 13:26
    Fredrik Blomberg
    0

    I´m Reading about it now to figur out. The thing that make´s me unserten is that ther is no controllers folder in my Visual studio... enter image description here

  • Fredrik Blomberg 6 posts 76 karma points
    Oct 27, 2015 @ 08:25
    Fredrik Blomberg
    0

    Hey!

    Can someone help me to find the controller in my project? Can´t find any controllers folder as the examples. Is it possible to search?

Please Sign in or register to post replies

Write your reply to:

Draft