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
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.
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?
As you see I've tried extending both PublishedContentWrapper and the generated content model.
My controller:
I'm using BeginUmbracoForm for routing
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!
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.
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
is working on a reply...