asp.net mvc - Multiple Dynamically Populated Drop Down Lists -
I have a page that has about 10 drop down lists that are generated from my SQL database. What's the best way? I was going to use a stored procedure with LINQ back to multiple result sets, but it looks a bit more I have another way of doing this? Using HtmlHelpers or something like that?
As everyone is confused by this, I will be elaborate.
- It is not with caching, it is not
- Do not do this with ASP.NET controls like DopDownList, I have tagged it as ap.net-mvc
- Behind this code-model, I thought how clearly it was clearly clear from this question originally tagged as ASP.NET MVC
The problem is that many results set on the page are necessary for the drop down list HTML!). So I have a drop down list for Badger's own favorite breed, a drop list for how many birthday lists you have, how many clouds in the sky today are all dynamically populated (please note, I jokingly I am a financial system on which I work). I need to stay on all my watch pages, but I do not want to use the IMTible Returnal Return Type in a LINQ stored procedure to bring back many result sets. It just gets messy.
So in basic form, I want about 10 drop down lists on my watch page, which come in data from all the databases (which are constantly changing). What is the best way to see them?
I just pass the required data if you want strongly typed access, then multiple Look in the ViewData dictionaries or as a special visual model, then use HtmlHelper.DropDownList () to display the actual drop down.
Vulnerely typed solution
controller
ViewData ["Data1"] = some repository .GetList (); ViewData ["Data2"] = Some Repositoty.GetList (); See Return ();
See
& lt;% = html.DropDownList ("Data1")%> & Lt;% = Html.DropDownList ("Data2")%>
Highly written solution
See model
public class DataViewModel {public IEnumerable & lt; String & gt; Data 1 {Receive; Set; } Public IEnumerable & lt; String & gt; Data 2 {Receive; Set;}}
controller
var model = SomeRepository.GetModel (); // DataViewModel returns an example of the return view (model);
See
& lt;% = html.DropDownList ("Data1", New SelectList (Model.Data1))%> & Lt;% = Html.DropDownList ("Data2", New SelectList (Model.Data2))%>
Comments
Post a Comment