tags:

views:

26

answers:

1

So 2 questions, I have my html.multiselectlist working fine, however I want to do 2 things...

  1. Set a default selected value from my list
  2. 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).ToList()
    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
A: 

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.

Lazarus
The List is populated through my viewmodel, which in turns just gets passed to my view afterwards.... that works fine.... I also just managed to figure out how to append additional static values to my existing Ienumerable list.... now I just need to figure out how to set a default....
denisb
Look at this http://msdn.microsoft.com/en-us/library/dd470158.aspx, you provide a list of SelectedItem which indicates the 'selected' items, just provide a list of 1 with your default item.
Lazarus