Here Mudassar Ahmed Khan has explained with an example, how to use For Each loop for populating DropDownList using Model in ASP.Net MVC Razor.
HTML SELECT element will be created in View and a For Each loop will be executed over the Model to create and add HTML OPTION elements to the DropDownList.
The Selected Value of DropDownList is easily available using Model or using Request.Form collection, but in order to get the Selected Text, the Selected Text is copied to a Hidden Field using jQuery and then it is fetched inside Controller in ASP.Net MVC Razor.
↧