Persisting Select Menus on Postback with FluentHtml and ASP.NET MVC
Last night I was having some problems with a simple piece of functionality using ASP.NET MVC and FluentHtml (the MvcContrib flavor). When a user selected from a menu, which in this case caused a form to be posted back to the server, upon postback the user’s selection was cleared. The post happened and the corresponding behavior would occur, but the selection had been cleared.
Take the class below. The select menu will be binding to a generic list of these Site classes.

I create a view model for the page that’ll be displaying a form and allowing the user to select a few things.

In the FluentHtml, I use the Selected method, then pass in the value of the view model’s SelectedSiteId property. When the user posts the form, FluentHtml wires up the menu to the correct item.

Happy Coding!