我想用@html.ListBox 提交一个List数据,但现只能提交@html.ListBox 选中的项,有没有方法提交LIST中的全部内容。因我通过选择,在@html.ListBox 动态增加数据。有没有其它表单控件,或用其它方法接交。谢谢 !

解决方案 »

  1.   

    碰到这种情况,我一向都是在页面加个Html.Hidden,JS获取ListBox所有的Text和Value及Selected,拼成字符串放到Hidden,然后在Controller取了再拆
      

  2.   

    可以采用1楼的,另外若表单name属性相同,亦可提交数组对象到Controller
      

  3.   

    简单的,比如你要提交checkbox勾选项到后台,那么View页面如:
    <input type="checkbox" name="selectedCity" value="北京" id="1" />
    <input type="checkbox" name="selectedCity" value="上海" id="2" />
    <input type="checkbox" name="selectedCity" value="广州" id="3" />
    ...
    controller里action就可以以这种方式接受:
    public ActionResult AddCity(string[] selectedCity)
    {
    ...
    }
      

  4.   

    非常感谢你的回答,但我是要提交ListBox中的内容,不是常用的input中的内容,你有其它方法吗?谢谢!
      

  5.   

    @Html.ListBox("AddItems", "***");public ActionResult Add(FormCollection fc)
    {
        var items = fc["AddItems"].Split(',');
        ...   
    }
    试试这个!~
      

  6.   

    json序列化成字符串,再反序列化回来
      

  7.   

    建议还是jquery处理所有listbox项,赋值到隐藏控件提交到Action吧!