ASP.NET MVC - Is IsPostBack still here?

前端 未结 11 2099
我在风中等你
我在风中等你 2020-12-09 17:09

I know, I know, I know. I shouldn\'t be doing webforms inside of MVC, I completely agree. But, the people who sign my paycheck will not approve a complete conversion of ou

11条回答
  •  被撕碎了的回忆
    2020-12-09 17:45

    If you have more than one form in an MVC page, you can add a hidden input within the form with a meaningful ID and test if it has a value. This way you do not need to have two separate handlers (one for get and one for post).

    So inf the page and inside the form:

     
    

    And in the controller :

    if (Request.Form["testForm"] != null)
            { 
            // ACTIONS FOR THE POSTED FORM
            }
    

    Hope it helps!

提交回复
热议问题