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

前端 未结 6 1952
感动是毒
感动是毒 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

    If you are giving same name for your radio buttons, then you can try the following code

    Controller

    [HttpPost]
    public ActionResult Index(string Answer)
    {
        return View();
    }
    

    View

    @using (Html.BeginForm("Index", "Demo"))
    {
           @Html.RadioButton("Answer", "A") A 
           @Html.RadioButton("Answer", "B") B 
    
        
    }
    

提交回复
热议问题