【发布时间】:2014-11-20 01:00:39
【问题描述】:
我正在开发一个页面,该页面在视图上显示来自服务的数据并允许用户对其进行过滤。 有一个国家列,允许用户过滤。
我无法找到一种创建复选框列表的方法,以便我可以在一个参数中获取所有选定的值,例如字符串 [] 国家/地区(在操作方法中)。
不能使用经典方式:
<input type="checkbox" name="countries" value="USA" />USA<br />
<input type="checkbox" name="countries" value="Canada" />Canada<br />
这确实会传递 URL 中的值,但不会在回发时将它们设置回(在回发时保持检查)。
我尝试使用 checkboxlist (http://goo.gl/TUvZzu),但对我的 Modal 来说似乎很复杂。
因为我的模型是一个非常直接的模型:
public string Title { get; set; }
public string Website { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string City { get; set; }
public string Zip { get; set; }
public string State { get; set; }
public string Country { get; set; }
感谢您的宝贵时间和帮助。
【问题讨论】:
-
你要使用jquery吗????
-
@Kartikeya:我可以,直到它解决了目的,但我需要将这些值发送到 Action Method 并将它们设置回来(保持状态)。
-
您是否有理由使用复选框列表被出售?为什么不能硬编码复选框并在控制器中构建
string[]? -
@MatthewHaugen :国家/地区列表在每次过滤时都会发生变化,我仍然可以通过迭代 Modal 来编写它们,但是我如何将值作为字符串 [] 提供给控制器,并通过剃须刀处理来设置值正确回发。 ?
-
创建一个视图模型,代表您想要显示和回发的内容
标签: c# asp.net-mvc asp.net-mvc-4 checkbox checkboxlist