Passing selected value from the radio buttons to the controller in MVC

前端 未结 6 1950
感动是毒
感动是毒 2020-12-10 04:58

I\'m trying to pass this selected radio button value from the razor view to the controller.... can someone please give me an idea how to do this?..................... My Vi

6条回答
  •  误落风尘
    2020-12-10 05:09

    Add the following source code to View:

    @Html.RadioButtonFor(m => m.Role, "1" ) A
    @Html.RadioButtonFor(m => m.Role, "0" ) B
    @Html.HiddenFor(m=>m.Role)
    

    You can put the selected value to this HiddenField: @Html.HiddenFor(m=>m.Role) and send it to controller via [HttpPost] prototype.

提交回复
热议问题