开发者

Introduced infinite loop, using jquery and MVC, can't find what is causing it

开发者 https://www.devze.com 2023-03-31 03:25 出处:网络
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.

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();
}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号