Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc Asp.NET MVC单选按钮无法从模型中的HttpPost工作_Asp.net Mvc - Fatal编程技术网

Asp.net mvc Asp.NET MVC单选按钮无法从模型中的HttpPost工作

Asp.net mvc Asp.NET MVC单选按钮无法从模型中的HttpPost工作,asp.net-mvc,Asp.net Mvc,我选择true或false,但我总是看到bool的默认值为false。请帮帮我 型号 public partial class Istek { public bool iade { get; set; } } 查看 我试过这个 @Html.RadioButtonFor(x => x.iade, "true", new { @id = "iade-evet", @class = "md-radiobtn" }) @Html.RadioButtonFor(x => x.iade,

我选择true或false,但我总是看到bool的默认值为false。请帮帮我

型号

public partial class Istek
{
   public bool iade { get; set; }
}
查看

我试过这个

@Html.RadioButtonFor(x => x.iade, "true", new { @id = "iade-evet", @class = "md-radiobtn" })
@Html.RadioButtonFor(x => x.iade, "false", new { @id = "iade-hayir", @class = "md-radiobtn" })
@Html.RadioButtonFor(x => x.iade, true, new { @id = "iade-evet", @class = "md-radiobtn" })
@Html.RadioButtonFor(x => x.iade, false, new { @id = "iade-hayir", @class = "md-radiobtn" })
还有这个

<input type="radio" id="iade-evet" name="iade" class="md-radiobtn">
<input type="radio" id="iade-hayir" name="iade" class="md-radiobtn">
还有这个

<input type="radio" id="iade-evet" name="iade" class="md-radiobtn">
<input type="radio" id="iade-hayir" name="iade" class="md-radiobtn">

但所有这些都不起作用

控制器


为单选按钮添加值。它不是一个自动发送true或false的复选框。单选按钮必须有一个值。

为单选按钮添加值。它不是一个自动发送true或false的复选框。单选按钮必须有一个值。

您的尝试基本正确,但没有中断。无需转义
id
<代码>类被标记,因为它是C#保留关键字

@Html.RadioButtonFor(x => x.iade, true, new { id = "iade-evet", @class = "md-radiobtn" })
@Html.RadioButtonFor(x => x.iade, false, new { id = "iade-hayir", @class = "md-radiobtn" })
现在检查呈现的HTML

<input id="iade-evet" name="iade" value="True" ... />
<input id="iade-hyir" name="iade" value="False" ... />
或视图中模型的标识符

@Html.RadioButtonFor(x => istek.iade, true, new { id="iade-evet", @class="md-radiobtn" })

你的尝试基本上是正确的,但没有失败。无需转义
id
<代码>类被标记,因为它是C#保留关键字

@Html.RadioButtonFor(x => x.iade, true, new { id = "iade-evet", @class = "md-radiobtn" })
@Html.RadioButtonFor(x => x.iade, false, new { id = "iade-hayir", @class = "md-radiobtn" })
现在检查呈现的HTML

<input id="iade-evet" name="iade" value="True" ... />
<input id="iade-hyir" name="iade" value="False" ... />
或视图中模型的标识符

@Html.RadioButtonFor(x => istek.iade, true, new { id="iade-evet", @class="md-radiobtn" })

非常感谢。我像这样改变了它的工作:)@Html.RadioButton(“istek.iade”,true,new{id=“iade evet”,@class=“md radiobtn”)谢谢。我像这样改变了它的工作:)@Html.RadioButton(“istek.iade”,true,new{id=“iade evet”,@class=“md radiobtn”})您的前两个代码片段都工作得非常好。如果它不适用于您,您也没有提供所有相关信息。我说“所有这些都不适用于HttpPost”。我和Jasen一起修改代码。再次感谢Jasen:)。您的前两个代码片段都非常好用。如果它不适用于您,您也没有提供所有相关信息。我说“所有这些都不适用于HttpPost”。我和Jasen一起修改代码。再次感谢杰森:)。