Home/MVC/MVC Razor : How to call controller from html radio button click event using Jquery

MVC Razor : How to call controller from html radio button click event using Jquery

In this post we will discuss about how to call the controller from the radio button click event using jquery.

HTML :

<div id=”radio”>
<input type=”radio” id=”Isactive” name=”Isactive” value=”1″ >Yes</input >
<input type=”radio” id=”Isactive” name=”Isactive” value=”0″ >No</input >
</div>

JQUERY :

$(document).ready(function () {
$(‘input[type=radio]’).live(‘change’, function()
{
alert($(this).val());
window.location = ‘@Url.Action(“UserDetail”, “AllUserDetail”)’;
});

});

Controller : AllUserDetailController

public ActionResult UserDetail()
{
//Perform action here
}

Explanation:

  • window.location = ‘@Url.Action(“UserDetail”, “AllUserDetail”)’;

UserDetail : This will be the name of the action
AllUserDetail : This will be the name of the controller.

 

READ  Donut Caching with Asp.Net MVC

 

3 Comments

  1. Anonymous May 2, 2013 at 11:44 am

    i like it…keep up.

  2. pravesh September 17, 2013 at 11:51 am

    In your jQuery have a mistake you forgot closing the ready method.

  3. thiyaguji September 23, 2013 at 11:40 am

    Thanks Pravesh… Updated…

Leave A Comment