单选按钮值在MVC中不变 [英] Radio button value not changing in MVC
问题描述
我们正在尝试从单选按钮更改值但是我们没有获得更改值
控制器
Lang_id是我的列名我绑定此列中的数据然后尝试更新绑定数据
表
以下是我的代码 -
@ Html.RadioButtonFor(model => p.Lang_id,1,p.Lang_id =='1'?new {@Checked =checked}:null)英语
@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
< b>我尝试了什么:
$ b $来自提交按钮的呼叫控制器功能 -
[HttpPost]
公共ActionResult UpdateAssistanceScheme(int Lang_id)
{
}
所以请帮帮我
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
推荐答案
什么是p?
您使用RadioButtonFor绑定到您的模型,所以你的视图的模型将是一个具有Lang_id字段的类,你绑定它就像
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
}
这篇关于单选按钮值在MVC中不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!