简体   繁体   中英

MVC ASP.NET Best way to get 52 textbox key/values from View to Controller

I'm hoping that it isn't to pass each as a parameter to the controller post method..

Have a grid of 52 text boxes representing weeks in a year, each will be containing a decimal value, need ALL of these passed back to the controller for mass updating of the database..

edit: Adding more details.

So my action Index(); returns a view with a list of 52 objects in it.

so

return View(dates);

inside the view I do a foreach for all the objects of that type in the model, and put their values into textboxes, I then want to change them and hit submit.

is there any way to get the updated list into my POST controller without having to give it 52 parameters with the id's of the textboxes?

Thanks a lot in advance!

edit: Maybe there is a way I can post the forum to the controller and iterate through the textbox controls and get out id/value, any idea how?

Check out this question. It should provide you with a better answer than using the FormCollection.

Complex model binding to a list

Hey, I got the solution I wanted after a bit of messing about. I just passed in the parameter "FormCollection myForm" and after a bit of exploring within that object I found my 52 values! Thanks for the help.

edit: I deleted this due to peer pressure probably over a year ago... but looking back on it I don't see what the problem was, aside from answering my own question..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM