How to call the controller from the radio button click ?
<div id="radio">
<input type="radio" id="Isactive" name="Isactive" value="1" />Yes</label>
<input type="radio" id="Isactive" name="Isactive" value="0" />No</label>
</div>
public ActionResult Index(CityList Obj,string Isactive)
{
return view();
}
You can use javascript to programatically submit a form. You should not have duplicate Id values for elements. Id's should be unique in a document.
@using (Html.BeginForm("Index", "Home"))
{
<!-- Your other form elements-->
<div id="radio">
<input type="radio" name="Isactive" value="Yes" />Yes
<input type="radio" name="Isactive" value="No" />No
</div>
}
Now you can listen to the change event on the radio button and use jQuery closest
method to get the form and call the submit
method.
$(document).ready(function () {
$("input[name='Isactive']").change(function () {
$(this).closest("form").submit();
});
});
Now when user make a selection on the radio button, the form will be submitted and the selected radio button's value attribute value will be available in your Isactive
parameter of your HttpPost index action method.
If you want to pass 1
and 0
, use a numeric type as the method parameter type instead of string
.