这是我的控制器调用的函数:
public ActionResult ExecuteRule(string rawSql, List<PdsMatchRuleParam> parameters)
{
var da = new DataAccess();
var ruleSql = ruleRawSql.Replace(@"{KEY}", "@pkey");
var dbParameters = new List<DataAccess.DbParameter>();
dbParameters.Add(new DataAccess.DbParameter("pkey", DbType.AnsiString, 4000,
parameters[4].DefaultValue));
var dt = da.Select(ruleSql, dbParameters.ToArray());
// Required to eliminate "A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'" exception
var db = JsonConvert.SerializeObject(dt,
Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
});
var result = new JsonResult()
{
ContentType = "application/json",
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
};
result.Data = db;
return result;
}
上述ds.Select调用正确返回数据。执行上述代码后,当我在浏览器中分析网络流量时,给我这个信息:
General:
Remote Address:[::1]:41678
Request URL:http://localhost:41678/Match.mvc/RuleResultsGrid? _=1436385801737
Request Method:GET
Status Code:401 Unauthorized
当我在即时窗口中检查Request的值时,这就是我得到的:
The name 'Request' does not exist in the current context
以下是我的一些JavaScript代码:
function execRule() {
$.ajax({
type: 'POST',
url: "ExecuteRule",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
ruleSql : PageState.SqlEditor.RuleSql.getValue(),
parameters: PageState.RuleParameters
}),
}).done(function(obj) {
PageState.RuleResultsGrid = response.queryResultsContainer;
bindRuleResults();
});
}
我错过了什么?这是我在JavaScript中没有正确设置的东西吗? 'Request'属性是否需要有一个值,因为当在同一个控制器中调用另一个函数时,'Request'也不存在,但是它正确返回了Kendo网格的数据?以下是在填充数据网格的同一控制器中执行其他方法的网络日志:
General:
Remote Address:[::1]:41678
Request URL:http://localhost:41678/Match.mvc/ExecuteRuleSet
Request Method:POST
Status Code:200 OK
请注意我的应用程序支持身份验证,但我在开发过程中完全关闭了它,因此我不应该因为权限问题而收到“401 Unauthorized”错误。似乎由于某种原因ASP.NET MVC没有生成响应页面。有没有人有什么建议? TIA。
更新
好的,我发现了一个问题 - 在execRule函数中我将url设置为不正确地设置为规则结果网格url: "RuleResultsGrid"
的名称,而不是控制器操作的名称。
现在我收到了这个错误:
Uncaught ReferenceError: response is not defined
at Object.eval (eval at evaluate (unknown source), <anonymous>:1:1)
at Object.InjectedScript._evaluateOn (<anonymous>:895:55)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
at Object.InjectedScript.evaluateOnCallFrame (<anonymous>:954:21)
at Object.<anonymous> (http://localhost:41678/Scripts/Match/eiq.match.config.js:617:45)
at fire (http://localhost:41678/Scripts/jquery/1.9.1/jquery.js:1037:30)
at Object.self.fireWith [as resolveWith] (http://localhost:41678/Scripts/jquery/1.9.1/jquery.js:1148:7)
at done (http://localhost:41678/Scripts/jquery/1.9.1/jquery.js:8084:14)
at XMLHttpRequest.send.callback (http://localhost:41678/Scripts/jquery/1.9.1/jquery.js:8608:8)
答案 0 :(得分:0)
好的,我发现了问题 - 这是固定的execRule():
function execRule() {
$.ajax({
type: 'POST',
url: "ExecuteRule",
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({
ruleSql : PageState.SqlEditor.RuleSql.getValue(),
parameters: PageState.RuleParameters
}),
success: function (matchedList) {
PageState.RuleResult = matchedList;
var dataSource = new kendo.data.DataSource({
data: matchedList
});
Grids.RuleResultsGrid.setDataSource(dataSource);
updateButtonStates();
}
});
}