Complex model binding

I have a client dto that contains a bunch of fields and also contains a list.

Now I can become attached to him quite easily, and he will display the Client with all his addresses. The fact is that the user can delete and add addresses dynamically.

I thought about adding forms associated with each address, but then I end up with internal forms, and I know that browsers do not play so well.

Then I thought about using javascript, but if the address is deleted, I have to go through all the addresses and change their indexes (addresses [0] .City), because I noticed that if the indexes are out of order and the action takes ClientForm as a parameter, then only in the list, which have sequential indexes, and they begin with 0 -, are in the ClientForm.Addresses list.

Any other solutions that are easy to implement? Did I miss something?

+3
source share
2 answers

If you place a submit button with a different name on each address, but not form tags, your external form can check for a specific button and redirect to the correct action (for example, change address No. 1, delete address 3, etc.)

If you use jquery validation, one of the caveats is that the type of all the send buttons for the child should be set to cancel, so when clicked, their validation does not happen.

NTN

Dan

+1
source

addresses.Index, . ASP.NET MVC ( 2 ) addresses.Index , , addresses[index].property .

.

addresses.Index = 0
addresses.Index = 3

, ...

addresses[0].City
addresses[0].Street
addresses[3].City
addresses[3].Street

... ICollection<Address> .

, , Javascript , (.. , ..).

Phil Haack .

+1

Source: https://habr.com/ru/post/1715042/


All Articles