Antatrix Antatrix - 7 months ago 29
jQuery Question

MVC radiobutton didn't call ActionResult

I'm trying to call ActionResult by using JQuery. And doing something wrong, because query starts, but ActionResult in controller - not. Also I need to send value of checked radiobutton in it.


$("#allRows").on("change", function () {
var url = '@Url.Action("Index", "OrderManagment")';

if ($("#allRows").attr("checked") === "checked") {
$.post(url, { 'tableRows': $("#allRows").val() });


public IActionResult Index( string tableRows )
//some code

if (tableRows == "all")
return View(orders.ToList());
var rows = Int32.Parse(_context.Settings.FirstOrDefault().Value);
return View(orders.ToList().Take(rows));


<form asp-action="Index">
<div style="text-align: right;">
<label> Select count of rows in the table</label>
<label><input type="radio" id="allRows" name="tableRows" value="all"> All</label>
<label><input type="radio" id="settings" name="tableRows" value="settings" checked/> Settings </label>

Answer Source
$("#allRows").on("change", function () {
        var url = '@(Url.Action("Index", "OrderManagment"))';

        if ($(this).is(":checked")) {
            $.post(url, { tableRows: $("#allRows:checked").val() , function(data){
                alert(data );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download