[RESOLVED]Custom Radio Button selected Value in Jquery issue

Hi ,

I am not able to get selected radio button value.

UI rendered code-

When i select radio button,while am seeing UI rendered code,its not updated "checked" property. still its showing the below

<div
class="RadioButton">

<input
Qid="0"
Value="2"
aria-required="true"
data-val="true"
data-val-required="This
field is required."

id="rdo_0"
name="rnm_0"
type="radio"></input>

<label
id=’Name_2′>Item
2
</label>

</div>

<div
class="RadioButton"><input
Qid="0"
Value="2"
aria-required="true"
data-val="true"
data-val-required="This
field is required."

id="rdo_0"
name="rnm_0"
type="radio"></input>

<label
id=’Name_2′>Item
2
</label>

</div>

<div
class="RadioButton"><input
Qid="0"
Value="2"
aria-required="true"
data-val="true"
data-val-required="This
field is required."

id="rdo_0"
name="rnm_0"
type="radio"></input>

<label
id=’Name_2′>Item
2
</label>

</div>

<span>&nbsp;</span>

<span
class="field-validation-valid
errortext"
data-valmsg-for="rnm_0"
data-valmsg-replace="true"></span>

HtmlHelper
class

am using the below html helper method to generate the radio buttons.

 public static MvcHtmlString RadioButtonForSelectList<TModel, TProperty>(
           this HtmlHelper<TModel> htmlHelper,
           Expression<Func<TModel, TProperty>> expression,
           IEnumerable<SelectListItem> listOfValues,string name
            )
        {
            var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
            var sb = new StringBuilder();

            if (listOfValues != null)
            {
                // Create a radio button for each item in the list 
                foreach (SelectListItem item in listOfValues)
                {
                    // Generate an id to be given to the radio button field 
                    var id = string.Format("{0}_{1}", metaData.PropertyName, item.Value);

                    // Create and populate a radio button using the existing html helpers 
                    var label = htmlHelper.Label(id, HttpUtility.HtmlEncode(item.Text));
                    TagBuilder textBox = new TagBuilder("input");
                    textBox.Attributes.Add("type", "radio");
                    textBox.Attributes.Add("name", "rnm_"+name);
                    textBox.Attributes.Add("id", "rdo_" + name);
                    textBox.Attributes.Add("Qid", name);
                    textBox.Attributes.Add("Value", item.Value);
                   
                        textBox.Attributes.Add("aria-required", "true");
                        textBox.Attributes.Add("data-val", "true");
                        textBox.Attributes.Add("data-val-required", "This field is required.");
                        var radio = textBox.ToString(TagRenderMode.Normal);
                  
                   // var radio = htmlHelper.RadioButtonFor(expression, item.Value, new { id = id }).ToHtmlString();
                    // Create the html string that will be returned to the client 
                    // e.g. <input data-val="true" data-val-required="You must select an option" id="TestRadio_1" name="TestRadio" type="radio" value="1" /><label for="TestRadio_1">Line1</label> 
                    sb.AppendFormat("<div class="RadioButton">{0}{1}</div>", radio, label);
                }
            }

            return MvcHtmlString.Create(sb.ToString());
        }


i have selected Last(3 rd radio button)..How can i get selected value in jquery?

please help me on that.

Thanks,

Sundar.

Hi,

Sundar1987

When i select radio button,while am seeing UI rendered code,its not updated "checked" property. still its showing the below

checked property of radio buttons won’t effect in view-source/ rendered code at browser, it will does in inmemory.

so try using jquery  which can get u the desired result (checked property value).

Leave a Reply