如何在 ASP.Net MVC 中保留 JQuery 搜索的价值
我有一个 MVC 视图,其中有一个搜索框。在 keyup 上,我执行 JQuery 搜索并将结果呈现到 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>
这一切都很好。我的问题是:
保留搜索的嵌套方法是什么,以便如果用户移动到另一个视图,他们会返回到同一组结果等?
我试图避免使用 ViewData 但在这种情况下可能没问题。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在,我已向 formViewModel 添加了一个可为空的参数,并从编辑页面传回。
For now, I've added a nullable parameter to the formViewModel and pass back in from the edit page.