开发者

MVC.NET MultiSelectList Questions

开发者 https://www.devze.com 2023-01-08 00:38 出处:网络
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

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

精彩评论

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