Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
We are trying to change value from Radio button but we not getting change value on
Controller
Lang_id is my column name i bind data in this column then try to update bind data in
Table
below is my code-


@Html.RadioButtonFor(model => p.Lang_id, "1", p.Lang_id == '1' ? new {@Checked = "checked"} : null) English
@Html.RadioButtonFor(model => p.Lang_id, "2", p.Lang_id == '2' ? new {@Checked = "checked"} : null) Hindi
@Html.RadioButtonFor(model => p.Lang_id, "3", p.Lang_id == '3' ? new {@Checked = "checked"} : null) Malyalam

What I have tried:

i call controller function from submit button-

[HttpPost]
public ActionResult UpdateAssistanceScheme(int Lang_id)
{

}

so please help me
Posted
Updated 5-Feb-18 23:21pm

1 solution

What is "p"?

You use RadioButtonFor to bind to your model, so your view's model will be a class that has a Lang_id field and you bind to it like

@Html.RadioButtonFor(model => model.Lang_id, "1", Model.Lang_id == '1' ? new { @Checked = "checked" } : null) English
@Html.RadioButtonFor(model => model.Lang_id, "2", Model.Lang_id == '2' ? new { @Checked = "checked" } : null) Hindi
@Html.RadioButtonFor(model => model.Lang_id, "3", Model.Lang_id == '3' ? new { @Checked = "checked" } : null)


The action will then be

[HttpPost]
public ActionResult UpdateAssistanceScheme(YourModelTypeHere model) 
{
   // value is in model.Lang_id
}
 
Share this answer
 
Comments
Member 12183079 6-Feb-18 6:19am    
foreach (var p in Model)
{
@Html.RadioButtonFor(model => model.Lang_id, "1", Model.Lang_id == '1' ? new { @Checked = "checked" } : null) English
@Html.RadioButtonFor(model => model.Lang_id, "2", Model.Lang_id == '2' ? new { @Checked = "checked" } : null) Hindi
@Html.RadioButtonFor(model => model.Lang_id, "3", Model.Lang_id == '3' ? new { @Checked = "checked" } : null)
}

p is Variable
F-ES Sitecore 6-Feb-18 6:33am    
You didn't think the fact that your code was actually in a loop was relevant enough to mention?

If you want to loop through items in a model you need to use indexes rather than "for each"

@for(int i = 0; i < Model.Count; i++)
{
@Html.RadioButtonFor(model => model[i].Lang_id, "1", Model[i].Lang_id == '1' ? new { @Checked = "checked" } : null) <text>English
@Html.RadioButtonFor(model => model[i].Lang_id, "2", Model[i].Lang_id == '2' ? new { @Checked = "checked" } : null) <text>Hindi
@Html.RadioButtonFor(model => model[i].Lang_id, "3", Model[i].Lang_id == '3' ? new { @Checked = "checked" } : null)
}

Your action will then be

public ActionResult UpdateAssistanceScheme(List<YourModelTypeHere> model)
Member 12183079 6-Feb-18 6:40am    
is there any other solution from this solution we have to change lots of pages and multiple location
Member 12183079 6-Feb-18 6:22am    
this is not working

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900