【发布时间】:2014-06-17 15:37:40
【问题描述】:
我有一个必须在今晚完成的小型 Web 应用程序,但我遇到了这个问题。我正在从 Index 视图向我的 HomeController 发出 ajax 请求,该请求传递了一些参数,包括字符串数组。
控制台中字符串数组的输出是:["text1", "text2"] 但在 actionresult 中我得到的是 string[0] = "text1, text1" 而不是 string[0] = "text1 " 和 string[1] = "text2"。
下面是我的代码!
jQuery 填充字符串数组(包裹在 onload 中):
var keywords = [];
$("#menu-jesus a").on("click", function () {
var keyword = $(this).text();
keywords.push(keyword);
getFilteredStatues();
showDescription(keyword);
$('#statue-info').hide();
});
阿贾克斯:
$.ajax({
type: "GET",
cache: false,
url: '@Url.Action("GetFilteredStatues")?height=' + queryString[0]
+ "&material=" + queryString[1]
+ "&keywords=" + keywords
+ "&itemsPerPage=" + itemsPerPage,
dataType: "html",
success: function (data) {
$("#pictures").html(data);
showSearchTerms();
hideSearchTermDiv();
getStatueInfo();
if (itemsPerPage >= 304) {
$(".more-results").hide();
}
},
});
操作结果:
public ActionResult GetFilteredStatues(string height, string material, string[] keywords, int itemsPerPage)
{
var h = height != "undefined" ? height : "";
var m = material != "undefined" ? material : "";
var statues = db.GetFilteredStatues(h, m, keywords, itemsPerPage);
return PartialView("PicturesResult", new IndexModel(statues));
}
感谢任何提示!谢谢。
【问题讨论】:
-
那么问题是什么?在
,上拆分它们并制作数组等等任何需要的东西
标签: jquery ajax arrays asp.net-mvc asp.net-mvc-4