MVC razor form with multiple different submit buttons?

前端 未结 13 1950
-上瘾入骨i
-上瘾入骨i 2020-12-04 12:59

A Razor view has 3 buttons inside a form. All button\'s actions will need form values which are basically values coming input fields.

Every time I click any of butto

相关标签:
13条回答
  • 2020-12-04 13:50

    This answer will show you that how to work in asp.net with razor, and to control multiple submit button event. Lets for example we have two button, one button will redirect us to "PageA.cshtml" and other will redirect us to "PageB.cshtml".

    @{
      if (IsPost)
        {
           if(Request["btn"].Equals("button_A"))
            {
              Response.Redirect("PageA.cshtml");
            }
          if(Request["btn"].Equals("button_B"))
            {
              Response.Redirect("PageB.cshtml");
            }
      }
    }
    <form method="post">
       <input type="submit" value="button_A" name="btn"/>;
       <input type="submit" value="button_B" name="btn"/>;          
    </form>
    

    0 讨论(0)
提交回复
热议问题