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
    Sep 16, 2023 @ 06:10
    Niall
    0

    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:

    [HttpPost]
    [AllowAnonymous]
    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

    Thanks!

  • Bruno Trigueiro 2 posts 72 karma points
    Sep 19, 2023 @ 00:35
    Bruno Trigueiro
    0

    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.

  • Pathini 7 posts 77 karma points
    Nov 06, 2023 @ 19:34
    Pathini
    0

    hi Bruno, I have problem with integrating a plugin base surfacecontroller. I have created a separate project to create forms and trying to upload to umbraco 10 . when I added surface controller project dll and then build return below error.

    Could not load file or assembly <

    I've already open a post but not got answer from umbraco members. enter link description here

Please Sign in or register to post replies

Write your reply to:

Draft