Copied to clipboard

Flag this post as spam?

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


  • Dan Mothersole 22 posts 109 karma points
    Sep 06, 2013 @ 12:38
    Dan Mothersole
    0

    Error passing in Umbraco.Web.Models.RenderModel

    I have just updated a test copy of my site from Umbraco 6.0.6 to 6.1.4 and now I am getting the following error when attempting to view a partial view.

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

    The situation if as follows, a user goes to reset their password and enters an email address. They are sent an email with a link that goes to my partial view. When trying to access this page the above error is now displayed.

    Example link -

    */umbraco/Surface/PasswordResetSurface/PasswordResetVerification/204ec89b-c387-476a-878c-41e7ec47e91a

    I have experimented and found that I can avoid this error by either commenting out following line in my password reset view - Layout = "~/Views/Shared/_Layout.cshtml"; or removing the @inherits UmbracoTemplatePage line from the _Layout view.

    Neither of these are a fix or tells me what is the actual cause of this error.

    Any help would be appreciated.

    Code

    Model -

        public class PasswordResetModel
    {
        [Required]
        [DataType(DataType.EmailAddress)]
        public string Email { get; set; }
    
        public string UniqueResetId { get; set; }
    
        public DateTime TimeStamp { get; set; }
    
        public string Verify { get; set; }
    
        [DataType(DataType.Password)]
        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        public string NewPassword { get; set; }
    
        [DataType(DataType.Password)]
        [Compare("NewPassword", ErrorMessage = "Passwords do not match")]
        public string NewPasswordConfim { get; set; }
    }
    

    Controller -

    public class PasswordResetSurfaceController : Umbraco.Web.Mvc.SurfaceController
    {
        [HttpGet]
        [ActionName("PasswordResetVerification")]
        public ActionResult PasswordResetStage2Get(PasswordResetModel model, string id)
        {
            return PartialView("PasswordResetStage2", model);
        }
    }
    

    PasswordResetView

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<UmbracoMVCAndBootstrap.Models.PasswordResetModel>
    
    @{
        Layout = "~/Views/Shared/_Layout.cshtml";
        ViewBag.Title = "ResetVerification";
    }
    
    <div class="span2 offset2">
    

    @using (Html.BeginUmbracoForm("PasswordResetVerification", "PasswordResetSurface", null, new { @class = "form-horizontal", @role = "form" }))
    {
        @Html.AntiForgeryToken();
    
    
    <div class="form-group">
            <label class="col-md-2 control-label" for="Email">New Password</label>
            <div class="col-md-4">
                <input type="password" class="form-control" id="NewPassword" name="NewPassword" placeholder="Password" value="@Model.NewPassword" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label" for="Email">Confim New Password</label>
            <div class="col-md-4">
                <input type="password" class="form-control" id="NewPasswordConfim" name="NewPasswordConfim" placeholder="Confim Password" value="@Model.NewPasswordConfim" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label" for="Email">Email address</label>
            <div class="col-md-4">
                <input type="Email" class="form-control" id="Email" name="Email" placeholder="Email" value="@Model.Email" />
            </div>
        </div>
        <div class="form-group">
            <div class="col-md-offset-2 col-md-4">
                <p class="Error">@TempData["ResetError"]</p>
                <button class="btn btn-primary" type="submit">Go!</button>
            </div>
        </div>
    
  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Sep 07, 2013 @ 20:50
    Andy Butland
    0

    I can't explain the reason for getting this error now you've upgraded Dan, but it might be related to how you are using the partial view.  These aren't intended to be browsed to via URLs in the same way that normal pages are.  That's why they are named partial views rather than views.  In fact normally it's considered best practice to decorate them with a [ChildActionOnly] attribute so they can't be pulled up in the browser via a the /umbraco/Surface/... type URLs.

    So I'd suggest try creating a standard page on your site, and in the template for that page reference the partial view using a @Html.Partial request.  That should hopefully sort it.

    Cheers

    Andy

Please Sign in or register to post replies

Write your reply to:

Draft