So 2 questions, I have my html.multiselectlist working fine, however I want to do 2 things...
- Set a default selected value from my list
- Append a hardcoded value / entry within my list (which is pulling from a DB), which is basically a select "ALL" option.
This is my controller code, so is there where I need to perform this task, or directly within my view or viewmodel:
Inherits Controller
Dim _DB As New BlackBoxNormalizedEntities()
' Main / Default Lander for TFS Section
Function TFSMain() As ActionResult
Dim AccTypeList = (From m In _DB.LibAcctType Select m).ToList()
Dim TrxnTypeList = (From m In _DB.LibTrxnTyp Select m).ToLi开发者_StackOverflowst()
Dim ActnCodeList = (From m In _DB.LibActnCode Select m).ToList()
Dim viewModel As New TFS_VModel()
viewModel.AccType = AccTypeList
viewModel.Trxntype = TrxnTypeList
viewModel.ActnCode = ActnCodeList
viewModel.TStatus = viewModel.TStatus
Return View(viewModel)
End Function
You should construct and populate your MultiSelectList within the Action as part of your ViewModel rather than in the View and present that ViewModel to the View.
精彩评论