我是MVC的新手。当前,我有一个强类型的视图,并且使用两个Html.RadioButtonFor作为标签,代码类似于:

<label class="radio">
       @Html.RadioButtonFor(model => model.Incoming, true)IncomingItems</label>
 <label class="radio">
       @Html.RadioButtonFor(model => model.Incoming, false)OutgoingItems</label>
 <input type="hidden" id="isIncomingItem" value = "@Model.Incoming" />


我想要的是设置模型。当选择第一个单选按钮或将其设置为false时传入为true,然后我想在视图之前立即在视图中使用此模型属性(将此值分配给"isIncomingItem")整个表格都提交给服务器。

你们对我如何实现它有想法。非常感谢!

最佳答案

您的Incoming属性已经用所选值填充,并且可用于操作方法。如果要在隐藏字段中设置相同的值,请尝试以下操作

@Html.HiddenFor(m => m.Incoming,new { id = "isIncomingItem"})

10-08 05:00