我在MVC 4应用程序上使用MiniProfiler.我们有一个视图以模态呈现(使用Colorbox jquery插件).那个视图在其中有一个局部视图,其中ajax形式如下所示:
@using(Ajax.BeginForm("<action name>", "<controller name>", new {area="<area name>"}, new AjaxOptions
{
UpdateTargetId = "modal-body",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST"
}))
{
<html for form here>
}
Run Code Online (Sandbox Code Playgroud)
当我们提交表单时,它返回相同的局部视图以覆盖视图上的整个部分.发布时,MiniProfiler会抛出错误:SyntaxError:意外的令牌,
这发生在这个函数中:
var jQueryAjaxComplete = function (e, xhr, settings) {
if (xhr) {
// should be an array of strings, e.g. ["008c4813-9bd7-443d-9376-9441ec4d6a8c","16ff377b-8b9c-4c20-a7b5-97cd9fa7eea7"]
var stringIds = xhr.getResponseHeader('X-MiniProfiler-Ids');
if (stringIds) {
var ids = typeof JSON != 'undefined' ? JSON.parse(stringIds) : eval(stringIds);
fetchResults(ids);
}
}
};
Run Code Online (Sandbox Code Playgroud)
它期待一个json的guids数组,但是它得到了两次数组,如下所示:
"["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-45d9-bf59-c916b665458d"],["6de0e02c-e694-4d8a-ac22-ea6a847efe0e","970f6640-fe5b-45d9-bf59-c916b665458d" "]"
这会导致它在尝试解析数组时发出呕吐.我不确定为什么数组会重复.任何帮助将不胜感激.谢谢!
我刚刚进入实体框架4,并最终希望使用POCO将其包装在存储库模式中.我发现了一些我没想到的东西.看来,如果您创建上下文,向其添加对象(不保存上下文)并再次查询上下文,则它不会在结果中包含新对象.难道我做错了什么?它似乎应该返回我添加的内容,即使我还没有将结果保存回数据库.这是我的示例代码:
ShopEntities context = new ShopEntities();
// there is only 1 customer so far
var customers = from c in context.Customers
select c;
Console.WriteLine(customers.Count()); // displays 1
Customer newCustomer = context.Customers.CreateObject();
newCustomer.FirstName = "Joe";
newCustomer.LastName = "Smith";
context.Customers.AddObject(newCustomer);
var customers2 = from c in context.Customers
select c;
Console.WriteLine(customers2.Count()); // still only displays 1
context.SaveChanges();
var customers3 = from c in context.Customers
select c;
Console.WriteLine(customers3.Count()); // only after saving does it display 2
Run Code Online (Sandbox Code Playgroud)