Click here to Skip to main content
15,895,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Here I have taken four partial views in index.cshtml view page.

four partial views have different models.

In the popup content i am calling partial view of another form.

In that partial View I have taken 5 combo boxes and i want to bind data using entity model.

For that in controller I am passing one method which contains linq query for retrieving 5 fields data.

I have passed Viewbag and ViewData Variables for binding list and selected value.

On loading it takes more time.I want to load data after clicking a button not in page loading.

I want to know how to use the distinct linq queries for 5 different comboboxes with the same list.

Please suggest me best ways to achieve it.

What I have tried:

My Index Page

@model Tuple<DevExpress.DashboardWeb.WorkingMode, DashboardDemo.Models.vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data>
@*@model DashboardDemo.Models.ViewModel.KPIViewModel*@


 @Html.Partial("~/Views/Home/DashboardPartial.cshtml")

@Html.Partial("~/Views/TreeView/VirtualModePartial.cshtml")

@Html.Partial("~/Views/Home/ForecastGridPartial.cshtml")

@Html.Partial("~/Views/Home/PopupPartial.cshtml")


PopupPartial.cshtml

@model Tuple<DevExpress.DashboardWeb.WorkingMode, DashboardDemo.Models.vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data>
@*@model DashboardDemo.Models.ViewModel.KPIViewModel*@
@(Html.DevExpress().PopupControl(settings =>
           {
               settings.Name = "PopupControlSelectSub";
               settings.ShowOnPageLoad = false;
               settings.ShowMaximizeButton = true;
               settings.Width = 1200;
               settings.Height = 500;
               settings.CallbackRouteValues = new { Controller = "Home", Action = "Main_Menu" };
               settings.AllowDragging = true;
               settings.CloseAction = CloseAction.CloseButton;
               settings.PopupAnimationType = AnimationType.Slide;
               settings.HeaderText = "Main Menu";
               settings.Modal = true;
               settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
               settings.PopupVerticalAlign = PopupVerticalAlign.WindowCenter;
               settings.PopupElementID = "btnName_CD";
               settings.ScrollBars = ScrollBars.Horizontal;
               settings.SetContent(() =>
               {
                   Html.RenderPartial("Main_Menu");
               });
           }).GetHtml())


Main_Menu.cshtml

@Html.DevExpress().DockPanel(
        settings =>
        {
            settings.Name = "panel1";
            settings.PanelUID = "panel1";
            settings.HeaderText = "Requester's Perimeter";
            settings.VisibleIndex = 0;
            settings.Width = 2000;
            settings.Height = 200;
            settings.ShowHeader = true;
            settings.ShowCloseButton = false;
            settings.AllowResize = true;
            settings.OwnerZoneUID = "leftZone";
            settings.Styles.Content.Border.BorderStyle = BorderStyle.Solid;
            settings.Styles.Content.Border.BorderWidth = 1;
            settings.Styles.Content.Border.BorderColor = Color.FromArgb(0xBBD7E7);
            settings.Styles.Content.BackColor = Color.FromArgb(0xDBEBF4);
            settings.Styles.Content.Paddings.Padding = 0;
            settings.SetContent(() =>
            {
                @Html.DevExpress().Label(
                    s =>
                    {
                        s.Name = "Label1";
                        s.Text = "Req Section:";
                    }
                    ).GetHtml();
                @Html.DevExpress().ComboBox(
                    q =>
                    {
                        q.Name = "ddl_Req_Section";
                        q.PreRender = (s, e) =>
                        {
                            if (ViewData["GetReqSel"] != null)
                            {
                                MVCxComboBox c = s as MVCxComboBox;
                                c.SelectedItem = c.Items.FindByValue(Model.Item2.txt_Req_Section);
                            }
                        };
                        //var s = ViewData["GetReqSel"].ToString();
                        //q.Properties.DataSource = DashboardDemo.Models.MainMenu.GetRequiredSelection();
                        //q.CallbackRouteValues = new { Controller = "Home", Action = "Main_Menu"};
                        q.Properties.ValueField = "txt_Req_Section";
                        q.Properties.TextField = "txt_Req_Section";
                        q.Properties.ValueType = typeof(string);
                        q.Properties.NullText = "All";
                        q.Properties.DropDownStyle = DropDownStyle.DropDown;
                        
                    }
                    ).BindList(ViewBag.GetReqsellist).GetHtml();
                @Html.DevExpress().Label(
                   a =>
                   {
                       a.Name = "Label2";
                       a.Text = "Req IPT:";
                   }
                   ).GetHtml();
                @Html.DevExpress().ComboBox(
                    b =>
                    {
                        b.Name = "ddl_Req_IPT";
                        b.PreRender = (s, e) =>
                        {
                            if (ViewData["GetReqIPT"] != null)
                            {
                                MVCxComboBox c = s as MVCxComboBox;
                                c.SelectedItem = c.Items.FindByValue(Model.Item2.txt_Req_IPT);
                            }
                        };
                        b.Properties.ValueField = "txt_Req_IPT";
                        b.Properties.TextField = "txt_Req_IPT";
                        b.Properties.ValueType = typeof(string);
                        b.Properties.NullText = "All";
                        b.Properties.DropDownStyle = DropDownStyle.DropDown;
                    }
                    ).BindList(ViewBag.GetReqsellist).GetHtml();
                @Html.DevExpress().Label(
                  c =>
                  {
                      c.Name = "Label3";
                      c.Text = "Req Group:";
                  }
                  ).GetHtml();
                @Html.DevExpress().ComboBox(
                    d =>
                    {
                        d.Name = "ddl_Req_Group";
                        d.PreRender = (s, e) =>
                        {
                            if (ViewData["GetReqGrp"] != null)
                            {
                                MVCxComboBox c = s as MVCxComboBox;
                                c.SelectedItem = c.Items.FindByValue(Model.Item2.txt_Req_Group);
                            }
                        };
                        d.Properties.ValueField = "txt_Req_Group";
                        d.Properties.TextField = "txt_Req_Group";
                        d.Properties.ValueType = typeof(string);
                        d.Properties.NullText = "All";
                        d.Properties.DropDownStyle = DropDownStyle.DropDown;
                    }
                    ).BindList(ViewBag.GetReqsellist).GetHtml();
                @Html.DevExpress().Button(
                    e=>
                    {
                        e.Name = "Filter_On_Parameter";
                        e.Text = "Filter On Parameter";
                    }
                    ).GetHtml();
                @Html.DevExpress().Button(
                 f =>
                 {
                     f.Name = "Reset_Scope";
                     f.Text = "Reset Scope";
                 }
                 ).GetHtml();
            });
            settings.ControlStyle.Border.BorderStyle = BorderStyle.None;
        }
).GetHtml()


Home Controller.cs

public ActionResult Index()
       {
           GetReqSelection();
           WorkingMode workmode = new WorkingMode();
           vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data Current_Data = new vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data();
           var tuple = new Tuple<WorkingMode, vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data>(workmode, Current_Data);
           return View(tuple);
           //var BCVM = new Tuple<DevExpress.DashboardWeb.WorkingMode, vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data>(WorkingMode.Viewer,vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data.);
           //return View(new KPIViewModel());
           //string workingModeString = this.Request.QueryString["mode"];
           //var workingMode = !string.IsNullOrEmpty(workingModeString) && workingModeString == "designer" ? WorkingMode.Designer : WorkingMode.Viewer;
           //return View(workingMode);
       }
       void GetReqSelection()
       {
           using (var db = new KPIDataEntities())
           {
               var query = (from category in db.vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data
                            select new
                            {
                                category.txt_Req_Section,category.txt_Req_IPT,category.txt_Req_Group,category.txt_MP,category.txt_MP_Origin
                            }).Distinct().ToList();
               ViewBag.GetReqsellist = query.ToList();
               ViewData["GetReqSel"] = query[0].txt_Req_Section;
               ViewData["GetReqIPT"] = query[0].txt_Req_IPT;
               ViewData["GetReqGrp"] = query[0].txt_Req_Group;
               ViewData["GetMP"] = query[0].txt_MP;
               ViewData["GetMPOrigin"] = query[0].txt_MP_Origin;
               //KPIViewModel vw = new KPIViewModel();
               //vw.Current_Data.txt_Req_Section = query[0].txt_Req_Section;
           }
           //using (var db = new KPIDataEntities())
           //{
           //    var query = (from category in db.vw_100_QUERY_FOR_XLS_WEEK_IN_PROGRESS_016_Forecast_Follow_Current_Data
           //                 select new
           //                 {
           //                     category.txt_Req_IPT
           //                 }).Distinct().ToList();
           //    ViewBag.GetReqIPT = query.ToList();
           //    ViewData["GetReqIPT"] = query[0].txt_Req_IPT;
           //    //KPIViewModel vw = new KPIViewModel();
           //    //vw.Current_Data.txt_Req_Section = query[0].txt_Req_Section;
           //}
       }
Posted
Updated 11-Aug-17 0:45am
Comments
Graeme_Grant 11-Aug-17 2:39am    
There is a lot of code with third-party controls. Break it down to something simple:
1. Add new [Get] & [Post] methods on your controller
2. Add a new view with a button (post) and 5 data-bound lists (or ComboBoxes)
3. Add code to the [Post] method to get the data and return it to the view

Once you have this working, then wire up for actual view.
TarunKumarSusarapu 11-Aug-17 6:02am    
Would u please elaborate the scenario with example?
Graeme_Grant 11-Aug-17 6:49am    
I've gone one better and given you a proof-of-concept project... This is not an Ajax solution as it was not stipulated in the question.
TarunKumarSusarapu 11-Aug-17 2:43am    
Would u please elaborate the scenario with example?
Karthik_Mahalingam 11-Aug-17 4:50am    
use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

1 solution

Quote:
On loading it takes more time.I want to load data after clicking a button not in page loading.

As per above, to keep it simple, I've put together a Proof-of-Concept project. You can swap out my data and handling of your view data for your own testing.

Note: This is not an Ajax solution as it was not stipulated in the question.

Data Object to share with the view:
C#
public class TestData
{
    public bool IsLoaded { get; set; }
    public List<string> Answers1 { get; set; }
    public List<string> Answers2 { get; set; }
    public List<string> Answers3 { get; set; }
}

Controller:
C#
public class HomeController : Controller
{
    [HttpPost]
    public ActionResult TestListPost(TestData request)
    {
        TempData["load"] = request?.IsLoaded;
        return RedirectToAction("TestList");
    }

    [HttpGet]
    public ActionResult TestList()
    {
        if (TempData.ContainsKey("load") &&
            !string.IsNullOrWhiteSpace(TempData["load"].ToString()))
        {
            return View(new TestData
            {
                Answers1 = new List<string>
                {
                    "Answer 1 - 1",
                    "Answer 1 - 2",
                    "Answer 1 - 3"
                },
                Answers2 = new List<string>
                {
                    "Answer 2 - 1",
                    "Answer 2 - 2",
                    "Answer 2 - 3"
                },
                Answers3 = new List<string>
                {
                    "Answer 3 - 1",
                    "Answer 3 - 2",
                    "Answer 3 - 3"
                },
                IsLoaded = true
            });
        }
        return View(new TestData());
    }
}

The View:
HTML
@model WebApplication1.Models.TestData
@{
    ViewBag.Title = "TestList";
}

<h2>TestList</h2>

@if (!Model.IsLoaded)
{
    Model.IsLoaded = true;
    using (Html.BeginForm("TestListPost", "Home", FormMethod.Post))
    {
        <button type="submit">Load Answers</button>
    }
}
else
{
    <p>Results</p>
    if (Model.Answers1 != null) { @Html.Partial("Answers", Model.Answers1); }
    if (Model.Answers2 != null) { @Html.Partial("Answers", Model.Answers2); }
    if (Model.Answers3 != null) { @Html.Partial("Answers", Model.Answers3); }
}

And the Partial View:
HTML
<ul>
@foreach (var item in Model)
{
    <li>@item.ToString()</li>
}
</ul>

How it works:

1. When the view TestList action is initially loaded, only a button is shown. The view sets the Model.isLoaded = true ready for postback
2. Clicking the button posts the model back to the controller's action TestLoadPost
3. the TestLoadPost sets a temporary state variable in the TempData PropertyBag and redirects back to the form load action TestList
4. The TestList action checks if it needs to load the data and performs the task if the temp value is set
5. The view now loads and displays the data
 
Share this answer
 
v2
Comments
TarunKumarSusarapu 11-Aug-17 7:30am    
Hi Graeme_Grant,

Thank you for your explanation with the example.

I understood your example but here where should i call GetReqSelection() method.

I think it should be called in Post method of action in controller.
Graeme_Grant 11-Aug-17 7:33am    
The example does the loading in the Get not Post method. The post method takes the input or load state in this case and calls (RedirectToAction(...)) the get method. If it takes time to load the data, then make the method Async...
TarunKumarSusarapu 11-Aug-17 7:41am    
Here My requirement is first of all page is being loaded.After clicking the button it should display popup which contains partial view of Main_Menu.cshtml.
Here GetReqSelection() method which contains linq query to retrieve the data should be called after clicking the button.
Here I have created 4 partial views in index.cshtml.One of the partial view is popup.cshtml.
In that popup.cshtml i am rendering main_Menu partial view which contains the combobox.
Here I have taken two models and that is defined in the tuple.
Graeme_Grant 11-Aug-17 7:46am    
You want to load a page, then click a button that does a jQuery Ajax post to controller action method[^] request and populate the popup(?) or view(?) with the result data?
TarunKumarSusarapu 11-Aug-17 7:43am    
Please check the code which i mentioned here and suggest me the best way

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