Copied to clipboard

Flag this post as spam?

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


  • Huw Reddick 651 posts 2141 karma points
    Jul 01, 2022 @ 16:34
    Huw Reddick
    0

    Problem posting to surface controller

    I have a couple of issues.

    I have a page template called ProfileInfo.cshtml this template includes a partialview which contains a form which posts back to a surface controller.

    problem 1. If I declare the form using @using(Html.BeginUmbracoForm<PortalProfileSurfaceController>("SubmitForm") it adds the wrong action to the form (it adds the URL of the template page. I hava had to override the action to get it to post to the correct controller/action!

    problem 2. After overiding the action to get it to post to the controller, I get the following error

    Can only use UmbracoPageResult in the context of an Http POST when using a SurfaceController form
    

    when doing return CurrentUmbracoPage()

    Any thoughts?

  • Huw Reddick 651 posts 2141 karma points
    Jul 02, 2022 @ 06:58
    Huw Reddick
    100

    Managed to get it to work in the end. The problem was with passing the model to the forms partial view

    @await Html.PartialAsync("Forms/Profile/_ProfileDetails",vm)
    

    and using @model Mymodel in the partial view.

    If I moved myModel's init code to the partial view instead of passing from the main template page and used @inherits UmbracoViewPage instead of @model Mymodel in the partialView everything started working (except myModel was always empty in the controller), to fix that I had to do

    public IActionResult SubmitForm([Bind(Prefix="vm")]ProfileModel model)
    
Please Sign in or register to post replies

Write your reply to:

Draft