将列表集合传递给控制器

时间:2014-05-14 09:34:48

标签: c# asp.net-mvc

我有

查看:

  <div class="partialContents comiclist" data-url="@Url.Action("LoadAlphabetBook2", "book", new { delimiters = "#;;;0;;;1;;;2;;;3;;;4;;;5;;;6;;;7;;;8;;;9", keywords = "0 - 9", startLetter = "0", categoryIds = new List<int> { Model.categoryId } })">
    </div>


 <div class="partialContents comiclist" data-url="@Url.Action("LoadAlphabetBook2", "book", new { delimiters = "e;;;f;;;g;;;h", keywords = "E - H", startLetter = "E", categoryIds = new List<int> { Model.categoryId } })">
 </div>

脚本:

 var site = site || {};
site.baseUrl = site.baseUrl || "";

$(document).ready(function (e) {

    // locate each partial section.
    // if it has a URL set, load the contents into the area.

    $(".partialContents").each(function(index, item) {
        var url = site.baseUrl + $(item).data("url");

        if (url && url.length > 0) {

            $(item).load(url);

        }
    });
});

控制器

public ActionResult LoadAlphabetBook2(string delimiters, string keywords, string startLetter, List<int> categoryIds = null)
    {
       ......


    }

控制器正确获取除categoryIds之外的所有参数。实际上,它试图加载:

/书/ LoadAlphabetBook2?定界符=%23%3B%3B%3B0%3B%3B%3B1%3B%3B%3B2%3B%3B%3B3%3B%3B%3B4%3B%3B%3B5%3B %3B%3B6%3B%3B%3B7%3B%3B%3B8%3B%3B%3B9&安培;关键字= 0%20-%209安培; startLetter = 0&安培; categoryIds = System.Int32%5B%5D

如何让它正常传递像这样的列表而不是新的int []

1 个答案:

答案 0 :(得分:0)

您必须使用

将整数值显式转换为字符串
Model.categoryId.ToString( format ) ;

格式是可选的。