There are times when a collection of lookup to populate a drop down list is needed; this is very common. The usual solution is to create an Enumerable property in the view model to hold the lookup values, inject a service in the controller then in the action load the list to the view model and load the view. A complete example can be accessed at Pluralsight where dropdown lists are polulated in Razor views using the MVVM design pattern, Entity Framework, and Ajax.
Another approach is to load the lookup collection to the ViewData and access the values from the view or a template editor. This note is about a modification of this approach where the lookup collection is loaded into the ViewData using a Fiter Service which decorates the action requiring the loopkup collection.
The Filter
The following filter loads a collection of AssetTypes and converts the collection of DTOs into a SelectListItems using an extension method and loads the list on the ViewData.
The way to consume this filter service attribute is through the ServiceFilter, decorating the action with [ServiceFilter(typeof(AssetTypeCollectionAttribute))] this way:
Inject Service
Like any other service, the Filter Service needs to be injected in order to be discovered, therefore for an ASP.Net CORE application AssetTypeCollectionAttribute needs to be injected. In this example is added for the scope of the request:
Simple Drop Down List Editor
The editor template is simple, and can be reused for other lookup lists.
ViewModel and View
To end the note; the editor is invoked from the view passing two parameters in the ViewData; the index or key used to store the collection in the ViewData and the initial default message to load in the drop down list.
None of the above would work if the ViewModel does not have property AssetType decorated with [UIHint("ViewDropdown")]
To Table of contents
Subscribe to:
Post Comments (Atom)
A1 Repo: Simple Pagination for WCF Service Operation
It is never a good idea to paginate on the client. This post is about a simple pagination for a WCF service operation. For this work I nee...
-
There are times when a collection of lookup to populate a drop down list is needed; this is very common. The usual solution is to create an...
-
Motivation We have became accustomed to using design patterns to solve common and complex problems that recur often in software engineering ...
-
Bad Data Is No Better Than No Data: Then, Validate Ebenezer! After my previous post, Noding, MongoDBing With Mongoose: On the Account of t...
Nice blog and valuable for all people. Thank you for posting this.
ReplyDeleteInformatica MDM Training in Chennai
Informatica mdm training
Spoken English Classes in Chennai
IELTS Coaching in Chennai
Japanese Classes in Chennai
French Classes in Chennai
content writing course in chennai
Informatica MDM Training in OMR
Informatica MDM Training in Porur
Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post. price monitoring
ReplyDeleteUnderstanding the advantages of the SaaS model may require crucial changes to a software merchant's plan of action, software engineering and operational structure. Rainy Crack
ReplyDeletethank you for a great post. 50 Cent net worth
ReplyDeleteLove to read it,Waiting For More new Update and I Already Read your Recent Post its Great Thanks. 50 Cent net worth
ReplyDeleteThat appears to be excellent however i am still not too sure that I like it. At any rate will look far more into it and decide personally! accounting software Malaysia
ReplyDeleteThanks for this informative blog please keep posting more often as it might help someone who is looking to gain more knowledge.
ReplyDeleteSelenium Training in chennai | Selenium Training in anna nagar | Selenium Training in omr | Selenium Training in porur | Selenium Training in tambaram | Selenium Training in velachery
thank you for your interesting infomation. how do you buy likes on instagram
ReplyDeleteGenerate your own targeted business sales leads with laser precision on complete auto pilot with revolutionary CBT Web Scraper and Email Extractor Software. Scrape and extract business data from Google Maps, Google SERPs, Yellow Pages, Yelp, Facebook Business Pages, Twitter, LinkedIn and custom website lists. Download the only lead generation tool you will ever need right now. Software
ReplyDeleteI curious more interest in some of them hope you will give more information on this topics in your next articles. monero online wallet
ReplyDeleteI am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. Email Address Extractor Online
ReplyDeleteInteresting post. I Have Been wondering about this issue, so thanks for posting. Pretty cool post.It 's really very nice and Useful post.Thanks How is web scraping used in business?
ReplyDelete