Copied to clipboard

Flag this post as spam?

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


  • Ravi Motha 289 posts 499 karma points MVP 4x c-trib
    Dec 19, 2014 @ 10:42
    Ravi Motha
    0

    Issue with ViewPage and Model in Umbraco 7.19

    I have a umbrcao 7.1.9 web site and I have form built using a view page with a model

    @using ww.ClientName.Logic.Model.Content;
    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Temp>
    @{
    
        Layout = "_layout.cshtml";
    
    }
    
    @Html.Action("MyRegistration","RegisterSurface")
    

    The Model looks like this

     public class Temp : Base
        {
            public Temp(int id)
                : base(id)
            {
            }
    
    
            [DataMember(IsRequired = true, Name = "Account Number")]
            [Display(Name = "Account Number")]
            [Required(ErrorMessage = "An Account Number is required")]
            //reg-ex
            public string AccountNumber { get; set; }
    
            [DataMember(IsRequired = true, Name = "Supply Address Postcode")]
            [Display(Name = "Supply Address Postcode")]
            [Required(ErrorMessage = "A Supply Address Postcode is required")]
            //postcode Regex
            public string Postcode { get; set; }
    
            [Display(Name = "Email address")]
            [Required(ErrorMessage = "The email address is required")]
            public string EmailAddress { get; set; }
    
        }
    

    however when I switch @inherits Umbraco.Web.Mvc.UmbracoViewPage

    which is identical to Temp I get a

     public class RegistrationViewModel : Base
        {
            public RegistrationViewModel(int id)
                : base(id)
            {
            }
    
            [DataMember(IsRequired = true, Name = "Account Number")]
            [Display(Name = "Account Number")]
            [Required(ErrorMessage = "The Account Number is required")]
            //reg-ex
            public string AccountNumber { get; set; }
    
            [DataMember(IsRequired = true, Name = "Supply Address Postcode")]
            [Display(Name = "Supply Address Postcode")]
            [Required(ErrorMessage = "A Supply Address Postcode is required")]
            //postcode Regex
            public string Postcode { get; set; }
    
            [Display(Name = "Email address")]
            [Required(ErrorMessage = "The email address is required")]
            //add validation for email address// datatype
            public string EmailAddress { get; set; }
    
    }
    

    The model item passed into the dictionary is of type 'ww.Clientname.Logic.Model.Content.Temp', but this dictionary requires a model item of type 'ww.Clientname.Logic.Model.Content.RegistrationViewModel'.

    any help normally rewarded with hugs and love and sometimes beer.

    Ravi

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Dec 19, 2014 @ 14:21
    Dave Woestenborghs
    0

    What kind of templatepage or umbracoviewpage do you use in your master layout ?

    Dave 

  • Ravi Motha 289 posts 499 karma points MVP 4x c-trib
    Dec 19, 2014 @ 14:31
    Ravi Motha
    0

    I'm using this in my layout..

    @using ww.Clientname.Logic.Model.Content;
    @inherits UmbracoViewPage<Base>
    
  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Dec 19, 2014 @ 14:37
    Dave Woestenborghs
    0

    Can you inherit your layout from UmbracoTemplatePage ?

  • Ravi Motha 289 posts 499 karma points MVP 4x c-trib
    Dec 19, 2014 @ 14:51
    Ravi Motha
    0

    I've tried variations and that doesn't work as i don't pass the models I need to the pages..

    If it works with Temp, and registrationViewModel is exactly the same except for the name.. whya should one work and the other not..

  • Dave Woestenborghs 3325 posts 11170 karma points MVP 5x admin c-trib
    Dec 19, 2014 @ 14:54
    Dave Woestenborghs
    0

    Your master layout is used by all pages. So the model can change for different pages. It is hard to tell without the whole picture

    Dave

  • Ravi Motha 289 posts 499 karma points MVP 4x c-trib
    Dec 19, 2014 @ 15:11
    Ravi Motha
    0

    Ii have a Umbraco View Page

    @using ww.ClientName.Logic.Model.Content;
    @inherits UmbracoViewPage<Base>
    @{
        Layout = null;
        var member = Members.GetCurrentMember();
        var loggedIn = Model != null && Model.LoggedInCustomer != null;
    
    
    }
    
    <!DOCTYPE html>
    <!--[if lt IE 9]>
        <html class="IE8" lang="en">
    <![endif]-->
    <!--[if gte IE 9]><!-->
        <html lang="en">
    <!--<![endif]-->
    
    <head>
        @Html.Partial("Properties",Model)
    </head>
    
        <body>
    
            <div class="wrap">
                @Html.Action("Header", "HeaderSurface", new {member})
            </div>
    
            <div class="breakout">
                <div class="breakout-window">
                    <div class="breakout-content">
                        <h1>@Model.BreakoutTitle</h1>
                        <p>@Model.BreakoutText</p>
                    </div>
                </div>
            </div>
    
            <div class="wrap">
                  @if (!loggedIn)
                  {
                      @Html.Partial("MainMenu",Model)
                  }
            </div>
    
            <div class="wrap row">
                <section>
                    @RenderBody()
                </section>
            </div>
    
            <aside class="sidebar">
                <a href="#"><span>Live Chat</span></a>
            </aside>
    
            <div class="wrap row">
                <footer class="footer">
                     @if (!loggedIn)
                     {
                         @Html.Action("Footer", "FooterSurface")
                     }
                    @Html.Partial("StaticFooter")
                </footer>
            </div>
    
        </body>
    
    </html>
    

    I have a Base Document type and set a load of properties The only thing is the document type my register page inhrits from is called Temp.. because we had a bit of confusion there were a couple of registration document tyoes and I'm trying to kill the unnecessary pages and use a single layout template for reusability..

  • 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