Mapping individual buttons on ASP.NET MVC View to controller actions

后端 未结 3 2125
北荒
北荒 2021-02-08 18:01

I have an application where I need the user to be able to update or delete rows of data from the database. The rows are displayed to the user using a foreach loop in the .aspx

3条回答
  •  面向向阳花
    2021-02-08 18:55

    As rodbv said you want to use seperate

    elements.

    When you are using Asp.Net MVC or classic html (php, classic asp, etc) you have to forget the Asp.Net way of handling button presses. When a form is posted back to the webserver all the server knows about is simply "the form was sent, and contained the following input elements".

    Asp.net (standard) adds a wrapper round many of the standard html postback actions using javascript (the __doPostback javascript function is used almost everywhere) and this adds information about which input element of the form caused the postback and delivers it to the server in a hidden form variable. You could mimic this behavior if you really so desired, but I would recomend against it.

    It may seem strange 'littering' a page with many 's, however it will mean that the postback to the server will be lighter weight and should make everything run that little bit faster for the user.

提交回复
热议问题