Search code examples
asp.net-mvcdevexpress-mvc

Bind GridLookup control in shared layout mvc 5


I am using Devexpress MVC application where i used one GridLookup control in shared layout. I needed here some controller which will call a method on every request. For this purpose i used base controller and using ActionExecutingContext method where i am calling my menu loading and gridlookup loading. I am using viewdata to set the value and in shared view i used partial view of my GridLookup control where i am binding viewdata to GridLookup. Below is the Base controller used to load menu and filters of gridlookup.

protected override void OnActionExecuting(ActionExecutingContext context)
{
     base.OnActionExecuting(context);
     ProcessingMenus();
}

Below is the shared layout where i am using partialview of gridlookup control

@Html.Partial("_ReportFilter")

Below is the GridLookup control used in this partial:

@{
     var gridLookup = Html.DevExpress().GridLookup(settings =>
     {
         settings.Name = "LookupLobMultiple";
         settings.KeyFieldName = "Description";
         settings.GridViewProperties.CallbackRouteValues = new { Controller = "Manage", Action = "BindLOB" };
         settings.Properties.SelectionMode = GridLookupSelectionMode.Multiple;
         settings.Properties.TextFormatString = "{0}";
         settings.Properties.MultiTextSeparator = ";";
         settings.CommandColumn.Visible = true;
         settings.CommandColumn.ShowSelectCheckbox = true;
         settings.CommandColumn.SelectAllCheckboxMode = GridViewSelectAllCheckBoxMode.AllPages;
         settings.GridViewProperties.SettingsPager.Visible = false;
         settings.GridViewProperties.Settings.ShowGroupPanel = false;
         settings.GridViewProperties.Settings.ShowFilterRow = false;
         settings.Columns.Add("ID").Visible = false;
         settings.Columns.Add("Description").Caption = "Line of Business";
         settings.PreRender = (s, e) =>
         {
              MVCxGridLookup gl = (MVCxGridLookup)s;
              gl.GridView.Selection.SelectRowByKey(ViewData["LOB"]);
         };
    });
}
@gridLookup.BindList(ViewData["LobModal"]).GetHtml()

In the above GridLookup control you can see am binding data using viewdata which is loading in ProcessingMenus method. First issue here is in GridLookup i have used controller and action method also but this is not calling when i check and uncheck any value and showing Loading.... Second issue when after sometime if i again hit the url OnActionExecuting method is not calling due to it menus are not loading again.


Solution

  • I found the answer from Devexpress team is to call partial view in shared view use @{Html.RenderAction("action", "controller");} and then in that action call the partial view that need to show in shared layout with passing model data. and in partial view just bind the grid with the passed model.

    That's it.

    Thank you for all your suggestions.