passing checkbox and textbox values from a view form to a controller action
I have a vi开发者_如何学Goew with a form..this form has a textbox and a checkbox in it.
i also have a submit button in the form which points to an action in a controller.
my question is..how can i pass the values in the textboxes and the checked state of the checkboxes to the controller action?
the textboxes and checkboxes are not tied to a model.
thanks
You have two options.
The best option would be to create a ViewModel. This model doesn't need to have any logic or anything behind it, just a public get/set for the properties. This means you can also use the MVC validation, helpers and binding on the values and makes it easier to work with.
The alternative is for your action to accept a FormCollection, this is basically a dictionary with the form values, the keys being the name attribute on your form elements.
精彩评论