EUDM
EUDM

Reputation: 45

Check which Radiobutton is selected C#

In MVC ASP.NET C# i have a list with radiobuttons.

In my controller i need to check which of these values is selected in order to excecute the correct function

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

I was used to jQuery selecting the ID and then .value, but im not sure how to do this in 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);
   }

Upvotes: 1

Views: 1665

Answers (1)

Venkatesh
Venkatesh

Reputation: 1224

In your action method in the controller try as below,

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

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

Upvotes: 2

Related Questions