开发者

How to Preserve Value of JQuery Search in ASP.Net MVC

开发者 https://www.devze.com 2022-12-08 10:04 出处:网络
I have an MVC view where I have a search box.On keyup, I perform a JQuery search and render the results to a div>

I have an MVC view where I have a search box. On keyup, I perform a JQuery search and render the results to a div>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script language="javascript" type="text/javascript">   

$(document).ready(function() {
$("#SearchTextBox").keyup(function() {
    $("#MyEntityList").load("/MyEntity/IndexSearch/" + "?searchText=" + $('#SearchTextBox').val());
    });

    //trigger textbox on search - so back button works
    $("#SearchTextBox").trigger('keyup');
})

</script> 

<h2>MyEntitys&开发者_如何学Clt;/h2>

<div class="searchBar">           
        <%= Html.Encode("Search by entering a Surname or Company: ") + Html.TextBox("SearchTextBox") %>             
</div>

<div id="MyEntityList">   
        <% Html.RenderPartial("MyEntitySearchResults", Model); %>                     
</div>

<p>
    <%= Html.ActionLink("Create New", "Create") %>
</p>

This all works fine. My question is:

What's the nest way to preserver the search so that if a user moves to another view, they are returned to the same set of results etc?

I'm trying to avoid the use of ViewData but in this case is it may be OK.

Thanks


For now, I've added a nullable parameter to the formViewModel and pass back in from the edit page.

0

精彩评论

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