ASP.Net MVC with 2 Submit Buttons
I have a view with 2 submit buttons. Both must submit t开发者_运维技巧he form data to the controller, but the actions the perform are different.
If the user clicks Button A, the form is submitted, the model is modified, and the model is returned to the form with some updated information. I'd also like to make a visible if Button A was clicked. So, initially, the is not visible, but if button A has been clicked, when the view is re-displayed, the must be visible. (Possible?)
Then, if button B is clicked, the form is submitted, and the details are persisted to the database.
Is this possible? Can I do some JQuery actions (Make a table visible) and then submit to the controller, and when the view is re-drawn, the table will be visible?
There are two options
- Either use javascript to modify form action
- Use same action, than on the basis of button, move your logic into different functions.
Example for case 2:
<input type="submit" name="button" value="Save" />
<input type="submit" name="button" value="Delete" />
and in *action*,
if (formCollection["button"] == "Save")
{
}
else
{
}
精彩评论