This is a migrated thread and some comments may be shown as answers.

[Solved] PanelBar item with url from Ajax.Action

7 Answers 220 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joao
Top achievements
Rank 1
Joao asked on 28 Jan 2011, 03:09 AM
Hi,

I'm using MVC3 with the Telerik MVC Q3 2010 SP1 controls and I've encountered a road block while using the PanelBar.

I've sucessfully used the Ajax.ActionLink to create a test link and load a partialview into my html. Now i'm trying to make the PanelBar items behave just the same.
So, I'm basically trying to change from something like item.Url = Url.Action(....), and start using a Ajax.ActionLink. (Or something simillar) I've tried all that I could think of to make the Ajax.ActionLink work but nothing seems to do it.

Is this possible or should I capture the client side event and load the content 'manually'?

Thanks for your help,

João Caxaria

7 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 28 Jan 2011, 08:18 AM
Hi,

Check this demo. It implements the same requirements that you have.

Regards,
Peter
0
Joao
Top achievements
Rank 1
answered on 28 Jan 2011, 03:17 PM
Hi Peter,

Sorry, but I don't understand how that project can help me. Maybe I didn't explain my problem as I should:

I have my PanelBar fully complete with all the items I want. Now I want that when a PanelBarItem is clicked, instead of doing a get to the controller, I want a ajax request and replace another div in my page with the partial view that comes back.

If it's of any help, this is my panelbar:

@using Telerik.Web.Mvc.UI;
@model IEnumerable<UserMenuItem>
@{
    Html.Telerik().PanelBar()
            .Name("PanelBar")
            .HtmlAttributes(new { style = "width: 300px; float: left; margin-bottom: 30px;" })
            .ExpandMode(PanelBarExpandMode.Multiple)
            .SelectedIndex(0)
            .BindTo(Model, mappings =>
            {
                mappings.For<UserMenuItem>(binding => binding
                        .ItemDataBound((item, menuItem) =>
                        {
                            item.Text = menuItem.Text;
                            item.ImageUrl = menuItem.Image;
                            if (!string.IsNullOrEmpty(menuItem.Controller))
                            {
                                item.Url = Url.Action(menuItem.Action, menuItem.Controller, menuItem.Arguments);
                            }
                        })
                        .Children(rootMenu => rootMenu.Children));
 
            }).Render();
}

Now, instead of using the item.Url = Url.Action(...) I wanted to somehow use the Ajax.ActionLink(...). Is this possible?

Tthanks for your time,

João Caxaria
0
Chris
Top achievements
Rank 1
answered on 06 Sep 2011, 01:57 PM
Did you ever get an answer to this?

I can do a item.ContentUrl but that fills the PanelBar which I don't want to do.
I can do a item.Url butr that just takes me to another page.

I want to do a PartialView into another div on my current page based on the selection of an item in the PanelBar.
0
Atanas Korchev
Telerik team
answered on 06 Sep 2011, 02:19 PM
Hello Chris,

 This can be easily done like this:

item.Text = Ajax.ActionLink(...);
item.Encoded = false;

Setting encoded = false is required because the panelbar will html encode the text of the item by default.

Regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Chris
Top achievements
Rank 1
answered on 06 Sep 2011, 02:44 PM
Doh that's so obvious, however it didn't work.

If I do this, somewhere on my page outside of the PanelBar it works as expected

@Ajax.ActionLink("changeMeLater", "RoundMap", "Round", new {roundId = 14}, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace });

If I do this inside my PanelBar I get the horrible server error message CS1593: Delegate 'blah blah' does not take 1 arguments

item.Text = Ajax.ActionLink("changeMeLater", "RoundMap", "Round", new {roundId = round.RoundId}, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace });
item.Encode = false;
0
Atanas Korchev
Telerik team
answered on 06 Sep 2011, 03:06 PM
Hello Chris,

 I forgot that Ajax.ActionLink does not return a string. Try this:

item.Text = Ajax.ActionLink("changeMeLater", "RoundMap", "Round", new {roundId = round.RoundId}, new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "result", InsertionMode = InsertionMode.Replace }).ToHtmlString();

Kind regards,
Atanas Korchev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Chris
Top achievements
Rank 1
answered on 06 Sep 2011, 03:15 PM
yep did it, thanks for your help.

Anyone reading this later, I have a typo in one of the posts. It reads

item.Encode = false;

It should read

item.Encoded false;
Tags
PanelBar
Asked by
Joao
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Joao
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or