ASP.NET MVC Session State

后端 未结 1 461
迷失自我
迷失自我 2021-02-04 15:54

I am currently trying to create an upload control with progress bar in MVC using jquery. I keep running into a problem however in that mvc doesn\'t work in parallel threads?

相关标签:
1条回答
  • 2021-02-04 16:29

    You will lose your view state if you call an action that returns a View. You can pass data between actions using the TempData if you like, but that probably won't solve your problem. Sounds to me like what you want here is an action that will return a JSON element that you can call with some asynchronous javascript.

    For your action you would have:

    public ActionResult GetSuggestions(string searchText)
    {
        return Json(new { SearchText = searchText + "completestring"});
    }
    

    And then on your form you have some asynchronous javascript using jQuery:

    function startAutoComplete() {
        var searchText = $("#inputText").val();
        $.getJSON("/Search/GetSuggestions?searchText=" + searchText, null, autoCompleteResponse);
    }
    
    function autoCompleteResponse(data) {
        if (data.SearchText) {
            $("#inputText").val(data.SearchText);
            $("#inputText").select();
        }
    }
    

    This will allow you to get some information from your server without posting the form and keeping the viewstate of the client in tact.

    There is a full write up of the example here that might help.

    0 讨论(0)
提交回复
热议问题