MVC razor form with multiple different submit buttons?

前端 未结 13 1992
-上瘾入骨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");
            }
      }
    }
    
    ; ;

提交回复
热议问题