开发者

MVC.NET MultiSelectList Questions

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).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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜