我正在尝试在切换(单选按钮)上提交表单。
我使用 JQuery 提交表单如下:
形式:
@for (var item = 0; item < Model.Count(); item++)
{
<form id="myform" action="xx" controller="xxx" method="post">
<input type="hidden" asp-for="@Model[item].a" />
<input type="hidden" asp-for="@Model[item].b" />
<input type="hidden" asp-for="@Model[item].c" />
<input type="hidden" asp-for="@Model[item].d" />
<tr>
<td>
@Html.DisplayFor(model => model[item].a)
</td>
<td>
@Html.DisplayFor(model => model[item].b)
</td>
<td>
@Html.DisplayFor(model => model[item].c)
</td>
<td>
@if(Model[item].istrue)
{
<input asp-for="@Model[item].istrue" type="radio" value="@Model[item].istrue" class="form-check form-control"/> @Model[item].istrue
<input asp-for="@Model[item].istrue" type="radio" value="False" class="form-check form-control" />
}
else
{
<input asp-for="@Model[item].istrue" type="radio" value="@Model[item].istrue" class="form-check form-control" /> @Model[item].istrue
<input asp-for="@Model[item].istrue" type="radio" value="True" class="form-check form-control" />
}
</td>
</tr>
</form>
Javascript:
@section Scripts {
<script type="text/javascript">
$('input[type=radio]').on('click', function () {
console.log("trigger works");
$(this).closest("form").submit();
});
</script>
}
控制器:
[HttpPost]
public IActionResult someaction(somemodel s)
{
--
--
}
我在应该触发的控制器动作上放置了断点。
控件不去动作
但是,切换时console.log会打印消息
我不太明白我做错了什么!!!
项目链接
https://github.com/dev-agk/WebFormList
.NET 小提琴
dotnetfiddle.net/8IzLE8
斯蒂芬大帝
相关分类