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

[Solved] Rebind Menu (using model binding) depending on what is selected in a dropdownlist

1 Answer 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matt
Top achievements
Rank 1
Matt asked on 21 Jul 2011, 10:01 PM
Hi guys,
I'm relatively new to MVC so please forgive me if I am conceptually a little wrong in any of my thinking.
The scenario:

I have 2 entities Department and MenuItem. (Note: Using EF4.1 code first to built entities. Not that that really effects this question)
Departments can have many MenuItems and a MenuItem can be owned by many Departments. Also a MenuItem may have another MenuItem as a parent.
public class Department
{
  public int DepartmentId { get; set; }
  public string Name { get; set; }
  public virtual ICollection<MenuItem> MenuItems { get; set; }
}
 
public class MenuItem
{
  public int MenuItemId { get; set; }
  public string Name { get; set; }
  [MaxLength]
  public string Url { get; set; }
  public virtual ICollection<Department> Departments { get; set; }
  public int? ParentId { get; set; }
  public virtual MenuItem ParentMenuItem { get; set; }
}

Essentially what I am trying to do is have a dropdownlist of Departments and when a department is selected, the menu is 'rebound' to the correct set of MenuItems. A department could have up to 100 MenuItems and there could be 30 Departments.
I thought I could have had an action in my controller that would return JSON and then bind the JSON to the menu but I'm not sure I can do that? I have also tried passing a list of MenuItems (with a default selected department) via a ViewModel and used the model binding for the menu. From there I am not sure how I 'rebind' the menu to a new set of MenuItems when the selected department changes.
Any help or even a sample project would be amazing! I have looked through the demo's and looked at the examples that come with the MVC extensions and they still haven't helped.

1 Answer, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 22 Jul 2011, 07:28 AM
Hello Matt,

 The menu does not support population from javascript. Perhaps you can refresh the view which rendered the page when the user selects a value from the dropdown. This can be done like this:

location.href = "/Controller/Action?someparameter=" + dropdown.value;

Regards,
Atanas Korchev
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
General Discussions
Asked by
Matt
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or