簡體   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