本文介绍了Asp.net mvc弹出搜索问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我创建了一个视图页面并在弹出窗口中打开,弹出窗口我有一个搜索选项来搜索。当我点击搜索按钮时,弹出视图将作为视图页面打开,弹出页面将关闭 我的代码在下面 I have created a view page and open in pop up and in that pop up i have a search option to search.When i click search button the pop up view is opening as a view page and the popup page is getting closeMy code is below <script type="text/javascript"> $(function () { $("#dialog").dialog({ autoOpen: false, width: 400, resizable: false, title: "hi there", modal: true, open: function(event, ui) { //Load the CreateAlbumPartial action which will return // the partial view _CreateAlbumPartial $(this).load("@Url.Action("Gridview", "Home")"); }, buttons: { "Close": function () { $(this).dialog("close"); } } }); $('#Button1').click(function () { $('#dialog').dialog('open'); }); });</script><div id="dialog" title="Create Album" style="overflow: hidden;"></div><input id="Button1" type="button" value="button" /> PopUp视图是 ---------------------- ------------------------------ @model dynamic < script src =http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.jstype =text / javascript>< / script> < script src =https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.jstype =text /的javascript>< /脚本> < link href =http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css\"rel =stylesheettype = text / css/> < script src =../../ Scripts / jquery.validate.unobtrusive.min.jstype =text / javascript>< / script> @using(Ajax.BeginForm(Gridview,Home,新的AjaxOptions {UpdateTargetId =DivGrid})) { IDictionary< string,> searchConditions = new Dictionary< string,>(); if(TempData [SearchConditions]!= null) { searchConditions = TempData [SearchConditions] as Dictionary< string,>; } 这个。 TempData [SearchConditions] = searchConditions; string conditions1 = searchConditions.Keys.Contains(Conditions1)? searchConditions [Conditions1]:string.Empty; string conditions2 = searchConditions.Keys.Contains(Conditions2)? searchConditions [Conditions2]:string.Empty; PopUp view is----------------------------------------------------@model dynamic <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script><script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script><link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="../../Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script> @using (Ajax.BeginForm("Gridview", "Home", new AjaxOptions { UpdateTargetId = "DivGrid" })) { IDictionary<string,> searchConditions = new Dictionary<string,>(); if (TempData["SearchConditions"] != null) { searchConditions = TempData["SearchConditions"] as Dictionary<string,>; } this.TempData["SearchConditions"] = searchConditions; string conditions1 = searchConditions.Keys.Contains("Conditions1") ? searchConditions["Conditions1"] : string.Empty; string conditions2 = searchConditions.Keys.Contains("Conditions2") ? searchConditions["Conditions2"] : string.Empty; @ Html.Encode(Conditions1:) @Html.Encode("Conditions1: ") @ Html.TextBox(Conditions1,@ conditions1) @Html.TextBox("Conditions1", @conditions1) @ Html.Encode(条件2:) @Html.Encode("Conditions2: ") @ Html.TextBox(条件2,@ conditions2) < input type =Submittext =Search/> @ * @ Ajax.ActionLink(Account,Gridview,new AjaxOptions {HttpMethod =GET,UpdateTargetId =result,InsertionMode = InsertionMode.Replace,OnSuccess =openPopup}) * @ @ * * @ var grid = new WebGrid(来源:型号, fieldNamePrefix:grid_, defaultSort:OrderID, canPage:true, canSort:true, ajaxUpdateContainerId:DivGrid, pageFieldName:paging, sortFieldName:sortField, rowsPerPage:10); @Html.TextBox("Conditions2", @conditions2) <input type="Submit" text="Search" /> @*@Ajax.ActionLink("Account", "Gridview", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace, OnSuccess = "openPopup" })*@ @* *@ var grid = new WebGrid(source: Model, fieldNamePrefix: "grid_", defaultSort: "OrderID", canPage: true, canSort: true, ajaxUpdateContainerId: "DivGrid", pageFieldName: "paging", sortFieldName: "sortField", rowsPerPage: 10); @ grid.GetHtml( 列:grid.Columns( grid.Column(OrderID,OrderID), grid.Column(ProductID,ProductID), grid.Column(格式:( item)=> Html.ActionLink(编辑,编辑,新{id = item.OrderID})) ) ) @grid.GetHtml( columns: grid.Columns( grid.Column("OrderID", "OrderID"), grid.Column("ProductID", "ProductID"), grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.OrderID })) ) ) 页数: @ Html.Encode(grid.PageCount) 总记录: @ Html.Encode(grid.TotalRowCount) @ Html.Encode(grid.FieldNamePrefix) } ---------------- ------------------------------ 控制器 --- ----------------------------------------- public ActionResult Gridview() { IDictionary< string,> searchConditions = new Dictionary< string,>(); if(this.Request.Form.AllKeys.Length> 0) { searchConditions.Add(Conditions1,Request [Conditions1]); searchConditions.Add(Conditions2,Request [Conditions2]); } else { 对象值= null; if(this.TempData.TryGetValue(SearchConditions,out values)) { searchConditions = values as Dictionary< string,> ;; } } this.TempData [SearchConditions] = searchConditions; string conditions1 = GetSearchConditionValue( searchConditions,Conditions1); string conditions2 = GetSearchConditionValue(searchConditions,Co nditions2); NorthwindEntities da = new NorthwindEntities(); var result =(from s in da.test(2) where (string.IsNullOrEmpty(conditions1)|| s.OrderID == Convert.ToInt32(conditions1)) && (string.IsNullOrEmpty(conditions2)|| s.ProductID == Convert.ToInt32(conditions2)) select s).ToList(); this.ViewData.Model =结果; 返回PartialView(); } 私有静态字符串GetSearchConditionValue(IDictionary< string, > searchConditions,string key) { string tempValue = string.Empty; if(searchConditions != null&& searchConditions.Keys.Contains(Conditions1)) { searchConditions.TryGetValue(key,out tempValue); } 返回tempValue; } Page Count: @Html.Encode(grid.PageCount) Total Record: @Html.Encode(grid.TotalRowCount) @Html.Encode(grid.FieldNamePrefix)}---------------------------------------------- Controller-------------------------------------------- public ActionResult Gridview() { IDictionary<string,> searchConditions = new Dictionary<string,>(); if (this.Request.Form.AllKeys.Length > 0) { searchConditions.Add("Conditions1", Request["Conditions1"]); searchConditions.Add("Conditions2", Request["Conditions2"]); } else { object values = null; if (this.TempData.TryGetValue("SearchConditions", out values)) { searchConditions = values as Dictionary<string,>; } } this.TempData["SearchConditions"] = searchConditions; string conditions1 = GetSearchConditionValue(searchConditions, "Conditions1"); string conditions2 = GetSearchConditionValue(searchConditions, "Conditions2"); NorthwindEntities da = new NorthwindEntities(); var result = (from s in da.test(2) where (string.IsNullOrEmpty(conditions1) || s.OrderID==Convert.ToInt32(conditions1)) && (string.IsNullOrEmpty(conditions2) || s.ProductID == Convert.ToInt32(conditions2)) select s).ToList(); this.ViewData.Model = result; return PartialView(); } private static string GetSearchConditionValue(IDictionary<string,> searchConditions, string key) { string tempValue = string.Empty; if (searchConditions != null && searchConditions.Keys.Contains("Conditions1")) { searchConditions.TryGetValue(key, out tempValue); } return tempValue; }推荐答案 (function(){(function () { (#dialog)。对话框({ autoOpen:false,宽度:400,可调整大小:false, title:hi there, modal:true, open:function(event,ui){ //加载CreateAlbumPartial动作,返回 //部分视图_CreateAlbumPartial ("#dialog").dialog({ autoOpen: false, width: 400, resizable: false, title: "hi there", modal: true, open: function(event, ui) { //Load the CreateAlbumPartial action which will return // the partial view _CreateAlbumPartial (this).load(@ Url.Action(Gridview,Home)); },按钮:{关闭:function(){(this).load("@Url.Action("Gridview", "Home")"); }, buttons: { "Close": function () { 这篇关于Asp.net mvc弹出搜索问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-26 03:01