ASP.Net MVC 4 Form with 2 submit buttons/actions

前端 未结 7 1500
故里飘歌
故里飘歌 2020-11-28 21:45

I have a form in ASP.Net and razor.

I need to have two ways of submitting said form: one that goes through the Edit action, and another that goes throug

7条回答
  •  有刺的猬
    2020-11-28 22:19

    We can have this in 2 ways,

    Either have 2 form submissions within the same View and having 2 Action methods at the controller but you will need to have the required fields to be submitted with the form to be placed within

    ex is given here with code Multiple forms in view asp.net mvc with multiple submit buttons

    Or

    Have 2 or multiple submit buttons say btnSubmit1 and btnSubmit2 and check on the Action method which button was clicked using the code

    if (Request.Form["btnSubmit1"] != null)
    {
     //
    }
    if (Request.Form["btnSubmit2"] != null)
    {
     //
    }
    

提交回复
热议问题