Copied to clipboard

Flag this post as spam?

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


  • Dean 13 posts 123 karma points
    Oct 19, 2023 @ 15:28
    Dean
    0

    How to pass object to surface Controller?

    I'm creating a new site in Umbraco 10. One of the pages contains 10 fields which are filled in by the admin of the site.

    Once these details are displayed to the end user in a page, I have 2 more text fields which have been added to the view (not part of the original 10 fields), along with a button which when clicked should allow me to pick up all these fields and values and carry out other tasks.

    I won't list the 'other tasks' unless someone needs to know but if I can get the current pages values I'll know what to do.

    I have a SurfaceController. I added a @BeginUmbracoForm clause to the cshtml which contains this button and upon clicking the button it hits my controller action.

    The controller is declared

    Public void DoOneThing(MyDocumentType obj)
    

    But no data is present in obj.

    How could I set up the view to bring in the 10 fields plus any additional ones not part of the document type?

  • Huw Reddick 1929 posts 6697 karma points MVP 2x c-trib
    Oct 19, 2023 @ 15:37
    Huw Reddick
    100

    not 100% sure, but possibly something like

    Public void DoOneThing([Bind(Prefix="Model")]MyDocumentType model, string param1, string param2)
    
  • Dean 13 posts 123 karma points
    Oct 19, 2023 @ 15:52
    Dean
    0

    Hi

    Thanks, I missed the name element in my view against the input control.

    Putting that in along with your change, resolved it.

Please Sign in or register to post replies

Write your reply to:

Draft