引入了无限循环,使用jquery和MVC,找不到是什么原因造成的
我似乎以某种方式引入了无限循环。 我正在使用 MVC2 并尝试使用 jQuery post
或 ajax
- 但似乎两者都发生了。
这个想法是用户在文本字段中输入 ids,然后我在数据库中搜索 id,然后在网格中显示对象。
下面是代码:
<script type="text/javascript">
function bulk() {
var data = $("#textfield").val();
$.post("Search", { searchString: data });
}
</script>
Which posts to controller method:
[HttpPost]
public ActionResult Search(string searchString)
{
...
return View(viewModel);
}
问题是,(无论是使用 ajax
还是 post
)在文本框中输入 ids 并点击搜索按钮后,我得到了 stackoverflow。这似乎可能是由无限循环引起的,但我无法弄清楚为什么会发生。在这一行之后会发生什么: $.post("Search", { searchString: data });
我点击了操作方法: public ActionResult Search(string searchString)
然后一切正常,搜索db,添加到视图模型,然后在 return View(viewModel);
之后,我只是一遍又一遍地直接返回 public ActionResult Search(string searchString)
。
我完全不知道为什么会发生这种情况。有什么想法可能会发生什么吗?
编辑:bulk
通过按钮点击调用 < /code>
@Daniel,我得到 StackOverflowException
was unhandled
An unhandled exception of type 'System.StackOverflowException'
发生在 mscorlib.dll 中 如果我单击查看详细信息 - 无法计算表达式,因为当前线程处于堆栈溢出状态。
它出现在实体框架代码中
public Entities() : base("name=Entities", "Entities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
I seem to have introduced an infinite loop somehow.
I am using MVC2 and attempting to use jQuery post
or ajax
- but it seems to be happening for either.
The idea is the users enters ids into a textfield, then I search db for the id's and then display the objects in a grid.
Here is the code:
<script type="text/javascript">
function bulk() {
var data = $("#textfield").val();
$.post("Search", { searchString: data });
}
</script>
Which posts to controller method:
[HttpPost]
public ActionResult Search(string searchString)
{
...
return View(viewModel);
}
Problem is, (whether using ajax
or post
) I get stackoverflow after entering ids into the textbox and hitting the search button. It seems likely cause by infinite loop but I can't work out why it is happening. What happens is after this line:$.post("Search", { searchString: data });
I hit the action method: public ActionResult Search(string searchString)
then everything goes as normal, search the db, add to view model, then after return View(viewModel);
I just go straight back to public ActionResult Search(string searchString)
over and over again.
I'm at a complete loss to why this is happening. Any ideas what might be happening?
edit: bulk
is called through a button click <input type="submit" onclick="bulk()" value="Search" />
@Daniel, I get StackOverflowException
was unhandled
An unhandled exception of type 'System.StackOverflowException'
occured in mscorlib.dll
If I click View detail - Cannot evaluate expression because the current thread is in a stack overflow state.
It occurs in the Entity Framework code
public Entities() : base("name=Entities", "Entities")
{
this.ContextOptions.LazyLoadingEnabled = true;
OnContextCreated();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您看来,您是否有机会调用
@Html.Action()
帮助程序? (与@Html.ActionLink()
相反)您还应该能够只按 F5 来调试应用程序,让它爆炸,并检查调用堆栈以查找导致无限的样子。
In your view, are you calling
@Html.Action()
helper by any chance? (as opposed to@Html.ActionLink()
)You should also be able to just press F5 to debug the app, let it blow up, and inspect the Call Stack to find the offending code that's causing the infinite look.