I’m building a page within an MVC application that contains a drop down box that allows the user to select a from a number of financial periods.
For the purposes of making it clearer for our users, I’d like to append “(Current)” to the option that is the current financial period and potentially “(Latest)” to the previous period to represent the last full period. We can already determine which financial period we are in and subsequently the one previous and so on.
So let’s say the two options I’m looking to append to currently look like this:
- Period 11
- Period 12
and I’d like it them to read:
- Period 11 (Latest)
- Period 12 (Current)
The drop down is populated from a database, but I would like to append this text at the application level.
Is this something that is possible? If so, how? I’m at a bit of a loss as to how to go about it.
Thanks for any help in advance.
I assume you’re using some sort of
IEnumerableon your model/view model class to populate the items in the drop-down. When you construct this list, simply add your “(Current)” and “(Latest)” options before returning the model to your view. IfFinancialPeriodis a model/view model class like this:Then you could do this in your controller, assuming that your list of all Financial Periods retrieved from the database is a property on your model called
FinancialPeriods:Make sure you substitute values for
<something>and<somethingElse>that you can interpret correctly when the model is posted back to your controller.Edit – based on your comments and edits, something like this is more appropriate: