Submitting Edit form - Map formdata to MVC Model

Submitting Edit form - Map formdata to MVC Model

jacktrapjacktrap Posts: 14Questions: 6Answers: 0

Hello,

I want to simply map saved edited fields to a model in mvc. My form data is simply :

action: edit
data[10046][AccountName]: 10000
data[10046][DisplayName]: bob jane
data[10046][GivenName]: bobby

What model structure do I require for MVC to automatically map these values to my model?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin
    Answer ✓

    I don't believe there is a way in MVC to automatically map values in that structure. I might be wrong, but I think you would need to flatten it to something like:

    action: edit,
    AccountName: 10000
    DisplayName: bob jane
    GivenName: bobby
    

    You can do that using the ajax.data option.

    Of course the disadvantage of that is that you can only edit a single row at a time, which is why Editor submits it in the format shown above by default.

    The Editor .NET libraries will read that format without issue.

    Allan

This discussion has been closed.