【问题标题】:Array of integers as value for an option in a html select整数数组作为 html 选择中选项的值
【发布时间】:2012-10-05 19:09:19
【问题描述】:

我对我的 mvc3 c# 应用程序中的 <select> 标记的 <option> 有疑问。 我可以使用 <option> 标签将整数数组传递给操作吗? 我的意思是,像这样:

<select name="status_filter">
   <option value="1,2,3,4">All</option>
   <option value="2,3">Some</option>
   <option value="2">One</option>
</select>

在我的操作方法中:

public ActionResult Filter(int[] status_filter)

可以吗?

谢谢, 贡萨洛。

【问题讨论】:

    标签: html arrays asp.net-mvc-3 option


    【解决方案1】:

    默认情况下这不会绑定。您将需要一个自定义模型绑定器或将其作为 javascript 中的数组传递

    来自: in asp.net mvc, how can I pass an array of integers as a parameter

    $.ajax({ url: '@Url.Action("刷新", "日历")', 类型:'POST', 内容类型:'应用程序/json;字符集=utf-8', 数据:JSON.stringify({范围:范围,范围ID:范围ID}), 成功:函数(结果){ // ... } });

    或者使用您自己的模型绑定器:

    http://neimke.blogspot.com/2011/01/pass-array-of-integers-to-controller.html

    【讨论】:

      【解决方案2】:

      最后我必须将数组更改为“all”、“some”、“one”的字符串,然后在控制器上执行切换。

      【讨论】:

        猜你喜欢
        • 2015-03-22
        • 2012-01-17
        • 1970-01-01
        • 2015-02-06
        • 1970-01-01
        • 2021-10-20
        • 1970-01-01
        • 1970-01-01
        • 2019-09-23
        相关资源
        最近更新 更多