views:

50

answers:

1

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</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

A: 

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

Davy