[英]Pass multiple check box values into Controller in ASP.NET MVC
I have an Enum list. 我有一个枚举列表。 I create these check boxes with the Enum list dynamically.
我用枚举列表动态创建这些复选框。
Here is the Enum list: 这是枚举列表:
[LocalizableDescription(@"BankPos", typeof(Resources.DisplayNames))]
BankPos = 1,
[LocalizableDescription(@"PrarkingPlace", typeof(Resources.DisplayNames))]
PrarkingPlace = 2,
[LocalizableDescription(@"OutdoorPlace", typeof(Resources.DisplayNames))]
OutdoorPlace = 4`
I created the check box with foreach
in Html tag . 我用Html tag中的
foreach
创建了复选框。
Here are the check boxes: 这是复选框:
<div class="checkbox-container">
<% foreach (var feature in Model.Features)
{%>
<label>
<input type="checkbox" name="q5" />
<span><%= feature.Text %></span>
</label>
<%}
%>
</div>
Up to here every thing is fine. 到这里为止,一切都很好。 My check boxes are create in correctly .
我的复选框创建正确。
My problem is, how can I pass these check box values into controller? 我的问题是,如何将这些复选框值传递给控制器?
As I said I want to pass them multiple. 如我所说,我想多次通过。
Here is my controller 这是我的控制器
[HttpPost]
public ActionResult Review(ReviewMemberRatingViewModel model, HttpPostedFileBase picUpload)
{
return null;
}
You need to include the checkboxes in your model, and bind the values to them. 您需要在模型中包括复选框,并将值绑定到它们。 So when you change a value on the model, it will be available in your action result.
因此,当您更改模型上的值时,它将在您的操作结果中可用。 You could generate your inputs with numerical indexes or there is a great example of what you are doing while taking it a step further with an editor template here .
您可以使用数字索引生成输入,或者通过此处的编辑器模板进一步说明如何做,这是一个很好的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.