我想发送" name"作为控制器的参数,但控制器没有接收参数
$(document).ready(function () {
$("#btn1").click(function () {
var name = $("#search").val();
//name = "ali";
alert(name);
$.post("/Status/searchByName", { typeId: name }, function (data) {
document.write(data);
$.each(data, function (key, value) {
//document.write(data,value);
// Here you can iterate data one by one and process it.
});
}, "text");
});
});
这里是动作方法
[HttpPost]
public JsonResult searchByName(string name)
{
dbCRMEntities dbx = new dbCRMEntities();
var names = dbx.CONTACTS.Where(chk => name == chk.NAME);
return this.Json(names, JsonRequestBehavior.AllowGet);
}
此操作方法仅接收空
答案 0 :(得分:7)
您传递{ typeId: name }
,但您的方法需要一个名为name
将参数更改为
public JsonResult searchByName(string typeId)
或者将脚本调整为
$.post("/Status/searchByName", { name: name }, function (data) {