Copied to clipboard

Flag this post as spam?

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


  • Tom C 87 posts 222 karma points
    Dec 21, 2016 @ 10:29
    Tom C
    0

    "Cannot bind source type .. to model type Umbraco.Web.Models.RenderModel." bit of help needed

    So I have a page, say just has one button generated like this,

     using (Html.BeginUmbracoForm("GoAddPerson", "PersonSurface", null, new { name = "myForm" })) 
    
            {
              <input type="submit"/>
            }
    

    This then calls a controller method which aims to return a new view

     [ValidateInput(false)]
        [HttpPost]
        public ActionResult GoAddPerson()
        {
    
            var m = new myproj.Models.PersonAddModel();
            return View("~/Views/PersonAdd.cshtml", m); 
    
    
        }
    

    But when tried, it just throws the Exception in the subject line .. If I make my model inherit from RenderModel then it works fine, and that is what I usually do, however I understand it doesn't have to inherit from RenderModel and in this case it is not useful to .. so just wonder what I am doing wrong here, and why the exception?

    Thanks in advance for any help

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Dec 21, 2016 @ 12:25
    Dan Diplo
    103

    If you are trying to return a model to an Umbraco view then it will need to inherit from RenderModel, I believe.

    If you are just processing a model (eg. a contact form or login) and aren't returning it to a view, then you can use any plain POCO model.

  • Tom C 87 posts 222 karma points
    Dec 22, 2016 @ 10:59
    Tom C
    0

    Thanks a lot .. ok I get it now .. to not inherit from RenderModel I need to move the code into a partial view and call that with the model.

Please Sign in or register to post replies

Write your reply to:

Draft