TAN WhoAMI

TAN WhoAMI

  • NA
  • 291
  • 0

JavaScipt for RadioButton

Mar 29 2013 4:43 AM
using ASP.NET MVC....with its controller as

        [HttpGet]
        public ActionResult Index(string Section)
        {
            var query = from v in context.Schedules
                        where v.Section == Section
                        select v;
            return View(query);           
        }

I have this at Index.cshtml

Select your Section:<br />
@Html.RadioButton("Section", "All", true, new { onclick = "showResult(this)"})  All
@Html.RadioButton("Section", "Device", false, new { onclick = "showResult(this)"})  Device
@Html.RadioButton("Section", "Sensoric", false, new { onclick = "showResult(this)"}) Sensoric
@Html.RadioButton("Section", "SMT", false, new { onclick = "showResult(this)"})  SMT
@Html.RadioButton("Section", "Test System Built", false, new { onclick = "showResult(this)"}) Test System Built <br /><br />

with is JavaScript as:
<script>
    function showResult(radio) {
        var selected = radio.value;
        window.location = "/Schedules/?Section=" + selected.toString();
    }
</script>

such that when user clicks each Device, Sensoric, SMT and Test System Built radio button, those data from Device, Sensoric, SMT and Test System Built are displayed correctly.

How about when user clicks the 'All' radio button? I want all those data from Device, Sensoric, SMT and Test System Built to be displayed.

How should I modify the code? And the 'All' radio button to be checked from the Index.chtml first load, such that all data is loaded.

thanks.


Answers (2)