开发者

ASP.Net MVC with 2 Submit Buttons

开发者 https://www.devze.com 2023-02-11 06:34 出处:网络
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.

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

  1. Either use javascript to modify form action
  2. 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
{
}
0

精彩评论

暂无评论...
验证码 换一张
取 消