I am exploring a generic solution related to DropDownBox in Asp.net MVC with respect to loggedin User role. Following is the scenario:
If UserRole is X then the DropDown on webpageA must have multiple values.
If UserRole is Y then the Dropdown on webpageA must have single value and dropdown must be ReadONLY defaulted to single value.
Values will be provided by the controller through ViewBag to the view
Can someone help me with the Extension method for this scenario?
Here is a link to download the source code for MVC3. The file you’re looking for is mvc3-rtm-sources\mvc3\src\SystemWebMvc\Mvc\Html\SelectExtensions.cs. That file contains all of the Extension methods for the DropDownList and DropDownList for.
What you’d be looking for is something similar to the following:
That should at least be a good starting point with what you’re looking for. Without more details, I can only really give you pseudo-code. However, you should be able to tweak what you need from there.
Don’t forget to check out the different overrides that they have for all of the functions. You may not think you need them now, but it’s always nice to know that all of the options are there should something change later on. Do those like they have them, and just have those methods return the method you create call the method with all of the possible parameters, passing in null values where necessary.