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

[Solved] Ajax.ActionLink Menu Item Redirects

5 Answers 150 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jason
Top achievements
Rank 1
Jason asked on 08 Sep 2011, 05:46 PM
Hello,

I have created a Telerik Menu and I would like to use an Ajax.ActionLink aas the menu item.  I saw another thread that shows you how to do this and I was able to add the link.  However, when the link is clicked in the menu the link redirects to the linked page instead of calling it via ajax.  I have included jquery.unobtrusive-ajax.min.js so that is not it. I have tracked it down to when the scrip registrar calls:

jQuery('#Menu').tMenu();

When that is included (which is really important) then the ajax.actionlink items no longer work properly. I am not sure what extra code gets added to the click of a link that is causing this to fail.  All other Ajax.ActionLinks in my page that are not in the Telerik Menu work perfectly.

Please let me know if there is a solution so I can use Ajax links. This would be VERY helpful!

Telerik MVC (2011.2.712) Menu, jquery-1.5.1.min.js 
Html.Telerik().Menu()
.Name("MapMenu")
.Items(items =>
{
items.Add().Text(Ajax.ActionLink("View Legend", "Legend", new AjaxOptions { UpdateTargetId = "Legend", OnSuccess = "alertMe" }).ToHtmlString()).Encoded(false);
})
.Render();

function alertMe() {
    alert("Alert!");
}

5 Answers, 1 is accepted

Sort by
0
zhang
Top achievements
Rank 1
answered on 20 Dec 2011, 06:33 AM
I got the same problem.Can somebody tell us how to use ajax menu items?
0
Mahesh
Top achievements
Rank 1
answered on 29 Feb 2012, 05:53 AM
I too have the same problem.Can any one explain how to solve this problem?
0
Tomas
Top achievements
Rank 1
answered on 11 Mar 2012, 12:17 AM
I have the same problem, is there any solution?
0
Jon
Top achievements
Rank 1
answered on 10 May 2012, 10:13 PM
Same here
0
Daniel
Telerik team
answered on 15 May 2012, 01:01 PM
Hi,

When using unobtrusive Ajax the jQuery live method is used to attach to the click event and the Menu will stop the event. Disabling the unobtrusive Ajax should resolve the problem as in this case the OnClick event is added directly to the link. Another option is to use the menu OnSelect event to handle the request with custom code. For example:
Html.Telerik().Menu()
.Name("MapMenu")
    .Items(items =>
    {
        items.Add().Text("View Legend").Action("Legend", "Controller");
    })
.ClientEvents(events => events.OnSelect("onSelect"))
.Render();
function onSelect(e) {     
    var url = $(e.item).find("> a").attr('href');
    if (url){
        //prevent the navigation if the item url is specified
        // and make the request with jQuery
        e.preventDefault();
        $.ajax({
            url: url,
            success: function (result) {
   
            }
        })
    }
}


Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Menu
Asked by
Jason
Top achievements
Rank 1
Answers by
zhang
Top achievements
Rank 1
Mahesh
Top achievements
Rank 1
Tomas
Top achievements
Rank 1
Jon
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or