我想将参数发送到我的控制器。这是我的视图页面:
<div>
<li> <input name="chk" type="checkbox" value="1"> electronics </li>
<li> <input name="chk" type="checkbox" value="2"> Construction</li>
<li> <input name="chk" type="checkbox" value="1"> Hardware</li>
<div class="row service-block" id="results">
@Html.Partial("_searchPartial", Model)
</div>
</div>
$("input[type='checkbox']").on('change', function () {
var checkboxes = document.getElementsByName('chk');
var vals = "";
for (var i = 0, n = checkboxes.length; i < n; i++) {
if (checkboxes[i].checked) {
vals += "," + checkboxes[i].value;
}
}
if (vals) vals = vals.substring(1);
$.ajax({
url: "/Search/SearchWorkers",
type: "GET",
dataType: 'html',
data: { checkCategoriesId: vals,"City": "@ViewBag.City", "OrderBy": "@TempData["OrderBy"]" },
contentType: "text/html;charset=utf-8",
success: function (responce)
{
$("#results").html(responce);
},
error:function (xhr, ajaxOptions, thrownError)
{
alert("test");
}
})
});
这是我的控制器:首先我调用这个方法来保存 orderby 值。
[HttpGet]
public ActionResult SearchPaging(string ItemSearchText,string City, string OrderBy, int PageNo, string Zipcode, string Flag,string checkCategoriesId)
{
TempData["OrderBy"] = OrderBy;
return PartialView("_searchPartial", userDetailsModel.OrderBy(v => v.Fullname).ToPagedList(PageNo, 1));
}
[HttpGet]
public ActionResult SearchWorkers(string checkCategoriesId,string OrderBy,string Flag,string City, int PageNo = 1)
{
TempData["OrderBy"] = OrderBy
return PartialView("_searchPartial", userDetailsModel.OrderByDescending(p => p.CreatedDate).ToPagedList(PageNo, 1));
}
我检查了 tempdata 值,它在视图页面上显示值。
但是当我触发复选框更改事件并且我正在传递临时数据值时,我得到的是空值。
我不知道有什么问题
有人能弄清楚吗?