ASP.NET MVC 2 Conditionally show model objects in my view depending on dropdownlist value
Using ASP.NET MVC 2, I have a model for a view. The view has a dropdownlist of roles that is populated by the model and there is a list below that of checkboxes with a number of privileges. I want to show only specif开发者_开发问答ic privileges depending on the dropdownlist selected roleID and have it update the privileges everytime the dropdownlist changes. I know how to do this in web forms ASP.net with absolutely no problem but I cannot seem to figure out where to start in ASP.NET MVC. Can someone please advise me what I need to do or towards a tutorial that will show me what to do? I am a novice in MVC. Thanks.
In MVC, you have complete control over the HTML markup used. In this kind of situation, I would mark each checkbox with a bit of metadata, and then when the change event occurs on your drop down, you enumerate over all the check boxes on the page and then show / hide them as appropriate.
Basically, you can push all that logic down to the client side, instead of having to make a round trip.
The solution I used to solve my problem was to call $.getJSON on the change event of the dropdownlist which returned an array that I looped through and determined if the privilege should be shown.
精彩评论