繁体   English   中英

检查选择了哪个单选按钮C#

[英]Check which Radiobutton is selected C#

在MVC ASP.NET C#中,我有一个带有单选按钮的列表。

在我的控制器中,我需要检查选择哪个值才能执行正确的功能

 <div id="radioBtnList">
     <fieldset id="Stats">
       <form method="post">
        <input type="radio" class="opt" name="Statistics" value="Total" checked>Total
        <br>
        <input type="radio" class="opt" name="Statistics" value="Products">Products
        <br>
        <input type="radio" class="opt" name="Statistics" value="Mediators">Mediators
        <br /><br />

        <input type="submit" id="btnStart" value="Start"
               onclick="btnStart_Click" />
        <br /><br />
    </form>
</fieldset>

我习惯了jQuery选择ID然后选择.value,但是我不确定如何在C#中执行此操作

     [HttpPost]
      public ActionResult Index(StatisticsView) 
      {
         init(true);
         if (opt.value == "Total") // how do i write this correctly in c#?
        {
           ///some function here
        }

        else if (opt.value== "Products")
        {
           ///some function here
        }

        else if (opt.value == "Mediators")
        {
              ///some function here
       }
    return View(v);
   }

在控制器的操作方法中,尝试如下操作:

[HttpPost]
public ActionResult Index(StatisticsView v, string Statistics)
{
    init(true);
    if(Statistics   == "Total")
    {
       //function
    }

    else if(Statistics == "Products")
    {
       //function
    }
   return View(v);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM