Keep selected item after a post

4 posts, 0 answers
  1. Bram
    Bram avatar
    8 posts
    Member since:
    May 2012

    Posted 04 Apr 2013 Link to this post

    I've created a panelbar in the Layout:

    @(Html.Kendo().Splitter()
                .Name("mainsplitter") //The name of the splitter is mandatory. It specifies the "id" attribute of the widget.
                .Panes(panes =>
                {
                    panes.Add().Content(@<text>@Html.Action("_Panelbar")</text>)
                                .Resizable(true)
                                .Size("20%");
                    panes.Add().Content(@<text>
                                <section class="content-wrapper main-content clear-fix">
                                    @RenderBody()
                                </section>
                                </text>); //Add pane
                })
                )
    And a rendersection for the main content, it all goes well, but when I
    change the main content Model, the panelbar jumps to the first item.
    When I return only the ViewBag, and no Model, the panelbar is keeping
    the selected item.
    What have I to do for keep always the selected item ?

    And in the _PanelbarView:

    @model CPMPlanning.Models.CPMModelViewPanel

    @( Html.Kendo().PanelBar()
        .Name("PanelBar")  
        .SelectedIndex(Model.ObjectIDSelected)
        .ExpandMode(PanelBarExpandMode.Single)
        .BindTo(Model.ObjectTypes, mappings =>
        {
            mappings.For<CPMPlanning.Models.ObjectTypeView>(binding => binding
                    .ItemDataBound((item, objecttype) =>
                    {
                        item.Text = objecttype.ObjectTypeDesc;

                    })
                    .Children(o => o.Objects));
            mappings.For<CPMPlanning.Models.ObjectView>(binding => binding
                    .ItemDataBound((item, obj) =>
                    {
                        item.Text = obj.ObjectCode;
                        item.Url = Url.Action("Index", "CPMModel", new { id = obj.ObjectID });
                    })
                );
        })
    )

  2. Daniel
    Admin
    Daniel avatar
    2117 posts

    Posted 08 Apr 2013 Link to this post

    Hi,

    I am not sure if I understand correctly the exact scenario. Could you clarify how are you changing the model and how is the "ObjectIDSelected" value determined?

    Regards,
    Daniel
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Bram
    Bram avatar
    8 posts
    Member since:
    May 2012

    Posted 09 Apr 2013 Link to this post

    Sorry, The ObjectID selected is not used anymore, it was just testing..
    The problem is: First, I had this panelbar as a partial view in the index page, but for reasons I've replaced it to the Layout structure with a splitter, but now the " automatic selecteditem" is not working anymore.. If you put the panelbar back in the index, and even after a GET, the panelbar is select automatic the previous selected item (That's what I want).

    _Layout:
           @(Html.Kendo().Splitter()
                .Name("mainsplitter") //The name of the splitter is mandatory. It specifies the "id" attribute of the widget.
                .Panes(panes =>
                {
                    panes.Add().Content(@<text>@Html.Action("_Panelbar")</text>)
                                .Resizable(true)
                                .Size("20%");
                    panes.Add().Content(@<text>
                                <section class="content-wrapper main-content clear-fix">
                                    @RenderBody()
                                </section>
                                </text>); //Add pane
                })
                )
  5. Bram
    Bram avatar
    8 posts
    Member since:
    May 2012

    Posted 09 Apr 2013 Link to this post

    Hi I solved it by giving " expanded" and " selected" in the view, and then:

    @( Html.Kendo().PanelBar()
        .Name("PanelBar")  
        //.SelectedIndex(Model.ObjectDescSelected)
        .ExpandMode(PanelBarExpandMode.Single)
        .BindTo(Model.ObjectTypes, mappings =>
        {
            mappings.For<CPMPlanning.Models.ObjectTypeView>(binding => binding
                    .ItemDataBound((item, objecttype) =>
                    {
                        item.Expanded = objecttype.IsExpanded;
                        item.Text = objecttype.ObjectTypeDesc;
                    })
                    .Children(o => o.Objects));
            mappings.For<CPMPlanning.Models.ObjectView>(binding => binding
                    .ItemDataBound((item, obj) =>
                    {
                        item.Selected = obj.IsSelected;
                        item.Text = obj.ObjectCode;
                        item.Url = Url.Action("Index", "CPMModel", new { id = obj.ObjectID });
                    })
                );
        })
    )

Back to Top
UI for ASP.NET MVC is VS 2017 Ready