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

Load menu dinamically on ASP.NET

0 Answers 32 Views
Menu
This is a migrated thread and some comments may be shown as answers.
ITServices
Top achievements
Rank 1
ITServices asked on 10 Oct 2014, 09:44 AM
Hi guys, I just wanted to share this code in case anyone need it, because I didn't find nothing similar on the forum.

This example loads a kendo menu dinamically from an aspx page, getting the elements from a server method accessed by ajax

.cs file

 [WebMethod(EnableSession = false)]
        public static string GetToolsAdminProjects()
        {
            List<Project> toolsAdminProjectList = ProjectsHelper.GetToolsAdminProjectList();
            List<ContextMenuItem> result = toolsAdminProjectList.Select(e=> new ContextMenuItem
            {
                text = e.DisplayName,
                url = e.URL
            }).ToList();

            var serializer = new JavaScriptSerializer();
            string json = serializer.Serialize(result);
            return json;
        }

.aspx file 
<script type="text/javascript">

 $.ajax({
                 type: "POST",
                 url: "GridView.aspx/GetToolsAdminProjects",
                 data: "{}",
                 contentType: "application/json",
                 dataType: "json",
                 success: function (result) {
                     var d = jQuery.parseJSON(result.d)
                     var menu = $("#menu").data("kendoMenu");
                     menu.append(d);
                 }
             });

</script>

No answers yet. Maybe you can help?

Tags
Menu
Asked by
ITServices
Top achievements
Rank 1
Share this question
or