ASP.NET MVC ModelBinder不使用GET请求和/或jQuery AJAX?
当通过GET而不是POST调用MVC时,我似乎在让MVC填写自定义模型参数方面遇到了问题 我有一个JavaScript代码片段,它调用如下操作:ASP.NET MVC ModelBinder不使用GET请求和/或jQuery AJAX?,jquery,asp.net-mvc,ajax,modelbinder,Jquery,Asp.net Mvc,Ajax,Modelbinder,当通过GET而不是POST调用MVC时,我似乎在让MVC填写自定义模型参数方面遇到了问题 我有一个JavaScript代码片段,它调用如下操作: $.getJSON('<%= Url.Action("DoSearch") %>' + location.search, function(data) { if (data.Result == "OK") { location.href = location.href; }
$.getJSON('<%= Url.Action("DoSearch") %>' + location.search,
function(data) {
if (data.Result == "OK") {
location.href = location.href;
}
});
模型是:
public class SearchParameters
{
public string Query;
...
}
调用URL(通过firebug验证)类似于/DoSearch?Query=some+Query
。(也尝试了/DoSearch?searchParameters.Query=some+Query
,但没有成功)
无论我尝试了什么,我的参数总是显示为空(不是null,只是所有参数都初始化为默认值)
如果我这样定义动作:
public ActionResult DoSearch(string Query, ...)
然后我的参数被正确填充。然而,与模型不同
我假设:
a) 填充对象模型对GET请求都不起作用
b) 我做错了什么
有什么想法吗?谢谢。在类上绑定时需要公共属性 替换
public string Query;
与
至少我要做的就是让它在我的项目中发挥作用。。我不知道你是否还有其他问题。
哦,我以前也很好,所以应该能用
这是我的参数类:
public class Parameters
{
public int? page { get; set; }
public int? pageSize { get; set; }
public string[] columnsToDisplay { get; set; }
public string columnToSort { get; set; }
public bool? descending { get; set; }
}
未与字段绑定。在类上绑定时需要公共属性 替换
public string Query;
与
至少我要做的就是让它在我的项目中发挥作用。。我不知道你是否还有其他问题。
哦,我以前也很好,所以应该能用
这是我的参数类:
public class Parameters
{
public int? page { get; set; }
public int? pageSize { get; set; }
public string[] columnsToDisplay { get; set; }
public string columnToSort { get; set; }
public bool? descending { get; set; }
}
没有绑定字段。Oops,这确实是正确的。现在可以了。希望有更多关于这方面的文档。非常感谢。回答得好,托马斯+祝贺你!缺少文档称为“约定”。)哎呀,这的确是正确的。现在可以了。希望有更多关于这方面的文档。非常感谢。回答得好,托马斯+祝贺你!缺少文档称为“约定”。)