C# 编辑器内单选按钮的状态更改为不工作
我的主要模型课C# 编辑器内单选按钮的状态更改为不工作,c#,asp.net-mvc,razor,editorfor,C#,Asp.net Mvc,Razor,Editorfor,我的主要模型课 public class MainModel { public ProblemType? problemType { get; set; } public SubProblemType? subProblem { get; set; } } 枚举的 public enum ProblemType { ProblemA =1, ProblemB =2 } public enum SubPr
public class MainModel
{
public ProblemType? problemType { get; set; }
public SubProblemType? subProblem { get; set; }
}
枚举的
public enum ProblemType
{
ProblemA =1,
ProblemB =2
}
public enum SubProblemType
{
SubProblemTypeA =1,
SubProblemType =2
}
我还为两个枚举创建了自定义editortemplate(editortemplate/ProblemType.cshtml)
@Html.LabelFor(x => x, "ProblemA")
@if (Model == ProblemType.ProblemA)
{
@Html.RadioButtonFor(x => x, (int)ProblemType.ProblemA, new { @checked = "checked" });
}
else
{
@Html.RadioButtonFor(x => x, (int)ProblemType.ProblemA);
}
@Html.LabelFor(x => x, "ProblemB")
@if (Model == ProblemType.ProblemB)
{
@Html.RadioButtonFor(x => x, (int)ProblemType.ProblemB, new { @checked = "checked" });
}
else
{
@Html.RadioButtonFor(x => x, (int)ProblemType.ProblemB);
}
SubProblemType编辑器模板/SubProblemType.cshtml也与上面的视图相同
现在在我的主视图中,我尝试进行一些验证(客户端),如果用户选择ProblemA单选框,那么我只需显示子问题类型单选框
到目前为止,我在我的main视图中尝试了如下操作
<script type="text/javascript">
$(function () {
$("#problemType").on("change", StateChange(function () {
if ($("#chkYes").is(":checked")) {
$("#subProblem").show();
} else {
$("#subProblem").hide();
}
}));
});
</script>
@Html.EditorFor(x => x.problemType, new { @onchange = "StateChange();" })
@Html.HiddenFor(x => x.subProblem)
$(函数(){
$(“#problemType”)。关于(“更改”,状态更改(函数(){
如果($(“#chkYes”)。是(“:选中”)){
$(“#子问题”).show();
}否则{
$(“#子问题”).hide();
}
}));
});
@EditorFor(x=>x.problemType,新的{@onchange=“StateChange();”})
@Html.HiddenFor(x=>x.subProblem)
但是它不工作,当我在js中选择ProblemType单选按钮时,我没有被触发更改事件。什么意思:不工作?有错误吗?黑屏?@VillageTech我已经更新了问题,没有错误,js代码没有从单选按钮触发任何更改事件