jQuery的自动完成传递null参数传递给控制器​​在ASP.NET MVC 2 [英] jQuery autocomplete pass null parameter to the controller in ASP.NET MVC 2

查看:110
本文介绍了jQuery的自动完成传递null参数传递给控制器​​在ASP.NET MVC 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jQuery自动完成插件从 jQuery的网站
呼叫控制器URL作为回报,返回JSON。问题是发送给控制器的参数总是空

I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return json in return. The problem is the parameter sent to the controller is always null.

下面是在浏览器的jQuery code的自动完成:

Here is the in-browser jQuery code for the autocomplete:

$(document).ready(function() {
    var url = "/Building/GetMatchedCities";
    $("#City").autocomplete(url);
});

和这里是C#中的ASPNET MVC控制器签名:

and here is the ASPNET MVC controller signature in C#:

public JsonResult GetMatchedCities(string city)
{
    ..
    return this.Json(query, JsonRequestBehavior.AllowGet);
}

由于提前,

穆罕默德

推荐答案

试着增加城市的数据作为extraParms:

Try adding the city data as extraParms:

$("#City").autocomplete(url, {
extraParams: { city: $('#City').val() }
});

这是使用.VAL时,假设$('#城市')的类型是文​​本的输入

This is assuming the $('#City') is an input of type text when using the .val

根据您的反馈意见的答复是:

Based on your feedback the answer is:

控制器应该是:

public JsonResult GetMatchedCities(string q)
{
    ..
    return this.Json(query, JsonRequestBehavior.AllowGet);
}

jQuery的将是:

The jquery would be:

 $(document).ready(function() { 
    var url = "/Building/GetMatchedCities"; 
    $("#City").autocomplete(url); 
 });

这篇关于jQuery的自动完成传递null参数传递给控制器​​在ASP.NET MVC 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆