我正在创建一个CRUD应用程序,我的应用程序从一个Kendo输入框中获取一个字符串,并且需要将它发送到我的控制器,该控制器期待我从Jquery调用获得的字符串。但是,字符串没有到达我的控制器。我尝试了各种各样的方法,但我无法通过我的运输方式发送。我已经提出了断点,我可以确认我的Kendo Observable中的值已被提取。
我的数据源
var client = new kendo.data.DataSource({
transport: {
read: {
url: "Client/SearchClient",
contentType: "application/json; charset=utf-8",
dataType: "json",
},
我的控制器
public ActionResult SearchClient()
{
return View();
}
[HttpPost]
public ActionResult SearchClient(string name)
{
Repo repo = new Repo();
var result = repo.GetClient();
return Json(new
{
list = result,
count = result.Count
}, JsonRequestBehavior.AllowGet);
}
这是我的Kendo Observable
var viewModel = kendo.observable({
client: {
clientName: "",
clientNumber: "",
clientType: "",
},
dropdownlist: ["HCC", "Tax", "Audit", "Advisory"],
create: function (e) {
var userRequest = $("#clientname").val();
if (userRequest) {
client.read(userRequest);
}
if (!userRequest)
alert("Please Enter Client Name")
}
});
答案 0 :(得分:1)
Search Client方法想要POST,而不是GET?默认为GET。更改您的api方法以使用HttpGet,或将传输更改为方法:" post"阅读
var client = new kendo.data.DataSource({
transport: {
read: {
url: "Client/SearchClient",
contentType: "application/json; charset=utf-8",
dataType: "json",
method: "post"
},