Copied to clipboard

Flag this post as spam?

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

  • Niall 1 post 71 karma points
    1 week ago

    POST to surfacecontroller using extended view model - cannot bind model

    Hi there,

    I'm new to the newer versions of Umbraco but quite familiar with old versions. I'm using U10.4.

    Essentially, all I'm trying to do is have a set of forms using a custom view model. For this area I don't need any IPublishedContent data, but I'd like to keep the CurrentUmbracoPage() method so I'm using a surface controller.

    I am struggling to get it to post to the surfacecontroller using my custom view model. I have tried many solutions.

    Can somebody tell me the best approach?

    My view model?

     public partial class RegistrationViewModel : PublishedContentWrapped//RegistrationPage
        public RegistrationViewModel(IPublishedContent content, IPublishedValueFallback publishedValueFallback) : base(content, publishedValueFallback)

    As you see I've tried extending both PublishedContentWrapper and the generated content model.

    My controller:

    public async Task<IActionResult> Register(RegistrationViewModel page)

    I'm using BeginUmbracoForm for routing

     using (Html.BeginUmbracoForm<RegistrationPageSurfaceController>     ("Register"))

    Can somebody tell me how to post to a surface controller with a custom view model?

    The error i get is Cannot bind source content type Umbraco.Cms.Web.Common.PublishedModels.RegistrationPage to model type GloucestershireCollege.ViewModels.RegistrationViewModel. Even if i set the constructor to be RegistrationViewModel


  • Bruno Trigueiro 2 posts 72 karma points
    1 week ago
    Bruno Trigueiro

    Hi Niall,

    Take a look at this article explaining how to achieve that.

    I'm not sure if using the @Html.BeginUmbracoForm from a partial is a requirement, but i had some problems with it in the past.

    Hope it helps.

Please Sign in or register to post replies

Write your reply to: