0

I am struggling with the following problem. I have in my .Net 4 application with Razor Page a database query that is started with a button (upper part in the code) and now I want to send the value of the radio button group (lower part in the code) with it, is this feasible and if so how? I would like to do this, if somehow possible, only with one button. Maybe this is also possible with a ViewBag variable? How would you do that?

Many thanks in advance.

 <form method="post" id="queryForm" asp-controller="HomeController">
   <div class="input-group">
     <select id="sqlQuerriesDropDown" class="form-select" name="selectedQuery">
       @foreach (var SqlQuery in ViewBag.SqlQuerriesDropDown)
       {
         <option value="@SqlQuery.getQueryName()">@SqlQuery.getQueryName()</option>
       }
     </select>
     <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
     <!-- Schaltfläche Anzeigen -->
     <input type="submit" class="btn btn-primary" value="View result"/>
     <p>&nbsp;&nbsp;&nbsp;</p>
   </div>
   <div>
     <br />
     <label><b>Decimal separator</b></label><br />
     <label><input class="boost_radio" onklick="boostNo(1)" asp-for="Boost_No.Number" type="radio" name="mySeperator" value=0 ViewBag.RB="0" checked="checked" /> Comma</label><br />
     <label><input class="boost_radio" onklick="boostNo(2)" asp-for="Boost_No.Number" type="radio" name="mySeperator" value=1 ViewBag.RB="1" /> Point</label><br />
     <span asp-validation-for="Boost_No.Number"></span><br />
     <input type="submit" value="submit" name="myDelimitter" id="submit" />
   </div>
  </form>
Michael 7
  • 1
  • 2

1 Answers1

0

This codes should help you. Please replace your controller names.

public ActionResult Index(FormCollection form)
 {
  string[] optionArray = Request.Form.GetValues("selectedQuery");
  return View();
 }

A last point is I strongly recommended to use models instead of viewbag.

cancan
  • 59
  • 6
  • I have already a [HttpGet] public ActionResult Index() { ... } and a [HttpPost] public ActionResult Index(string selectedQuery) { ... } in this HomeController, the next ActionResult Index(FormCollection form) will not work. – Michael 7 Feb 09 '23 at 15:44
  • I think method is POST on form. But on controller you used GET method. Change method on controller to POST. – cancan Feb 09 '23 at 16:08