Click here to Skip to main content
16,011,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 close

My code is below

XML
<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 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.TextBox("Conditions1", @conditions1)

@Html.Encode("Conditions2: ")

@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(
columns: grid.Columns(
grid.Column("OrderID", "OrderID"),
grid.Column("ProductID", "ProductID"),
grid.Column(format: (item) => Html.ActionLink("Edit", "Edit", new { id = item.OrderID }))

)
)


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;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900