sparklzrocks
sparklzrocks

Reputation: 39

how to access @Html.RadioButtonFor in jquery

i have a coded a radio button in MVC razor.below is the code for it.

 @{
           var LinkRadioName = "_Link";
            var ContentRadioName ="_Content";
            var TextRadioName = "_Text";
            var ExternalLinkRadioName ="_ExternalLink";
            var FilelistRadioName ="_Filelist";


            @Html.RadioButtonFor(m => m.MenuType, true, new { @id = LinkRadioName })
            @Html.Label("Link")
            @Html.RadioButtonFor(m => m.MenuType, false, new { @id = ContentRadioName })
            @Html.Label("Content")
            @Html.RadioButtonFor(m => m.MenuType, true, new { @id = TextRadioName })
            @Html.Label("Text")
            @Html.RadioButtonFor(m => m.MenuType, false, new { @id = ExternalLinkRadioName })
            @Html.Label("External Link")
            @Html.RadioButtonFor(m => m.MenuType, true, new { @id = FilelistRadioName })
            @Html.Label("File List")

        }

can any one help me ,as to how can i access this radiobutton set in jquery:

i have a code like this

@Html.RadioButton("TypeOfmenu", 1)Link
@Html.RadioButton("TypeOfmenu", 2)Content
@Html.RadioButton("TypeOfmenu", 3)Text
@Html.RadioButton("TypeOfmenu", 4)ExternalLink
@Html.RadioButton("TypeOfmenu", 5)Filelist

and i access it very easily in jquery like

 $("input[name$='TypeOfmenu']").click(function () {

        var Selectedvalue = $(this).val();
});

is there any way to access the @Html.RadioButtonFor control in d same way like

 $("input[name$='MenuType']").click(function () {

        var Selectedvalue = $(this).val();
});

??????

please help me as i m very new in MVC as well as jquery.

Upvotes: 2

Views: 5106

Answers (1)

Dave Alperovich
Dave Alperovich

Reputation: 32490

Since you are accessing the values in your function with this.val(), you can just bind your event to all radio buttons

$(":radio").click(function () {

        var Selectedvalue = $(this).val();
        //OR
        //var Selectedvalue = this.value;
});

Upvotes: 4

Related Questions