我将Asp.NET用于Entity Framework 6的后端,并使用了fiddler对其进行了测试,并且可以与http方法一起正常工作,但是当我使用它时,它将无法正常工作。 错误: XMLHttpRequest无法加载localhost:52068 / api / empl ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我尝试从SmartTable完成当前tableState的asp.net映射。
我使用ASP.NET MVC 5。
我的angularjs呼叫看起来像这样:
usersService.getUsers({
start: start,
number: number,
tableState: tableState
}
).then(function(result) {
});
我的queryString参数如下所示:
number:10
start:0
tableState:{"sort":{"predicate":"location","reverse":false},"search":{"predicateObject":{"location":"gfdgd","service":"gfdgd","company":"gd","fullname":"john"}},"pagination":{"start":0,"number":10}}
当然,我尝试在asp.net中映射查询信息。 我的控制器动作如下所示:
public JsonResult GetUsers(SmartTableRequestModel request)
{
return GetJsonResult(new
{
});
}
我尝试绑定的模型如下:
public class SmartTableRequestModel
{
public SmartTableQueryModel TableState { get; set; }
public int Number { get; set; } // number is well-binded
public int Start { get; set; } // the start is well-binded too
}
public class SmartTableQueryModel
{
[JsonProperty("sort")]
public SmartTableSortModel Sort { get; set; }
[JsonProperty("search")]
public SmartTableSearchModel Search { get; set; }
[JsonProperty("pagination")]
public SmartTablePaginationModel Pagination { get; set; }
}
public class SmartTableSortModel
{
[JsonProperty("predicate")]
public string Predicate { get; set; }
[JsonProperty("reverse")]
public bool Reverse { get; set; }
}
等等 ...
但是我没有在tableState模型中映射任何内容。 我的SmartTableRequestModel对象的TableState属性始终为null。
感谢您的以下帮助,Razvan
尝试发送请求数据,如下所示。
{"request" :{"TableState": {"sort":{"predicate":"location","reverse":false},"search":{"predicateObject":{"location":"gfdgd","service":"gfdgd","company":"gd","fullname":"john"}},"pagination":{"start":0,"number":10}}},"Number":10,"Start":1}
问题是我的getUsers是一个httpget方法,您无法将模型传递给httpget方法。
因此,我更改了资源以匹配httppost调用。
{
getUsers: { url: ci.domainPub + '/Management/GetUsers', method: 'POST', action: 'getUsers'},
},
在控制器中,操作将是:
[HttpPost]
public JsonResult GetUsers(SmartTableRequestModel request)
{
return GetJsonResult(new
{
});
}
通过这种机制,您可以发布smartTable插件的tableState,而无需基于服务器端进行任何处理和筛选/排序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.