Copied to clipboard

Flag this post as spam?

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


  • Phill 115 posts 288 karma points
    Mar 01, 2016 @ 19:35
    Phill
    0

    Model Values not posted to Controller, any ideas?

    Hi there,

    I'm using v 7.4.1 and have updated VS Extension to latest version so I'm able to build models using the new core modelsbuilder. All that works well. For one of my generated models I've added a partial class with the same name so that I can add a couple extra properties, one is a string and the other is actually another model. My Surface controller populates the string and the model and I'm able to render this data in my view. I now have all this wrapped in an UmbracoBeginForm and want to post back to an action in my SurfaceController. The generated model data gets posted to the controller but my string and model that are added after are null. For the string value for example I'm displaying it in the view using Html.EditorFor(m => m.GeneratedModel.Content.CustomStringProperty) Is there something I'm missing that would enable this data to be posted back to the controller?

    Thanks in advance. Phill

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 02, 2016 @ 12:44
    Jeroen Breuer
    0

    Hello,

    The Hybrid Framework also has some form examples, but I never use Html.EditorFor. What if you just create an input field where the name matches the property? Same as in the examples.

    Jeroen

  • Phill 115 posts 288 karma points
    Mar 02, 2016 @ 13:14
    Phill
    0

    That's for the response Jeroen, unfortunately that doesn't work. There are a few differences with the Hybrid sample and my scenario. Your contact page is just just using: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage and posts a simple form with input values and your Controller expects the ContactFormModel, a custom model created just for this.

    In my scenario, my page that is posting to the controller inherits the following: @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyModels.MasterModel<MyModels.Generated.ProductDetail>> Where ProductDetail is defined as a public partial class ProductDetail where ProductDetail is also a generated model from a document type. When I create an input as you suggest that is id/name = CustomStringProperty it doesn't post the value. If I use EditorFor the only difference is that the id/name is defined as Content_CustomStringProperty and Content.CustomStringProperty, again both of these are empty when posting my controller: [HttpPost] public ActionResult UpdateProduct(ProductDetail productDetail)

    This is just testing with simple string property, but my partial ProductDetail model also adds a property like: public ProductOptionsViewModel ProductOptions { get; set; } and this obviously doesn't work either. I can populate the view with data from DB just fine but nothing gets posted back.

    Any other thoughts on what I might be missing? Sorry code isn't formatted better, trying to post formatted code in this editor is a serious pain so I don't bother ;)

    Thanks again

    Phill

    p.s. I should also note that I've tried this whole front end editing thing using Html.Action to render a partial view but because I'm using an IContentFinder and rely on /ID added to the end of the URL that whole process falls apart as well. Return partial view and you loose page context/formatting, return CurrentUmbracoPage and things like dropdowns that have their values changed don't get updated, a caching issue I assume and RedirectToCurrentUmbracoPage leaves out the /ID at the end of the url, not to mention redirecting to a page just to load everything again because of a small update seems really inefficient. So I've had no luck with doing this using Partials and was hoping that using Page Model based on Generated Model would give me more consistent behaviour in line with standard MVC. If you have any other suggestions for approaches for front end editing of custom db tables I'm all ears :)

Please Sign in or register to post replies

Write your reply to:

Draft