zoukankan      html  css  js  c++  java
  • 如何给DropDownListFor设置默认值

    1、直接赋值:

    @Html.DropDownListFor(o => o.ParentId, ViewBag.root as IEnumerable<SelectListItem>,"默认值")
    

    2、在初始化时赋值:

    View层:

    @Html.DropDownListFor(o => o.ParentId, ViewBag.root as IEnumerable<SelectListItem>)
    

    Controller层:

    var parent = _dictionaryService.Where(o => o.IsDeleted == false && o.DisLevel == 1)
                                   .ToList()
                                   .Select(o => new SelectListItem()
                                   {
                                       Text = o.Name.ToString(),
                                       Value = o.Id.ToString()
                                    });
    ViewBag.root = parent;
    
    DictionaryViewModel viewModel = new DictionaryViewModel();
    viewModel.ParentId = id;
    
    string disOrder = "";
    disOrder = LoadDetailOrderNumber(id);
    viewModel.DisOrder = disOrder.AsInt();
    
    return View(viewModel);
    

      

  • 相关阅读:
    网络编程
    GUI编程
    Java数组
    Day24
    Day23
    Day22
    Day21
    Day20
    Day19
    Day18
  • 原文地址:https://www.cnblogs.com/maocs/p/4573821.html
Copyright © 2011-2022 走看看