zoukankan      html  css  js  c++  java
  • 在MVC中Controller为VIEW页面中的DropDownList赋值并锁定

    首先是枚举对象的遍历

    #region 类型列表框
                typeitems = new List<SelectListItem>();
                foreach (string i in Enum.GetNames(typeof(ServiceDocumentType)))
                {

    typeitems.Add(new SelectListItem { Text = ((ServiceDocumentType)

    Enum.Parse(typeof(ServiceDocumentType), i)).GetDescription(),

    Value = ((int)((ServiceDocumentType)

    Enum.Parse(typeof(ServiceDocumentType), i))).ToString() });

                }
                #endregion
    当有了上面基础后,再根据传入到当前实体,锁定当然选中的项
     ServiceDocumentCreateModel model = new ServiceDocumentCreateModel
                {
                    ProductID = entity.ProductID,
                    Content = entity.Content,
                    DownloadUrl = entity.DownloadUrl,
                    ImageUrl = entity.ImageUrl,
                    Level = entity.Level,
                    LinkUrl = entity.LinkUrl,
                    Title = entity.Title,
                    Type = new SelectList(typeitems, "Value", "Text", (int)entity.Type),
                    Status = new SelectList(statusItems, "Value", "Text", (int)entity.Status),
                };
    其中Type和Status都是SelectList类型,这样方便前台Model在VIEW中的展示。
    前台中展示就一句搞定:
      <%=Html.DropDownList("Type",Model.Type)%>
  • 相关阅读:
    程序员移居国外指南(1)-父母怎么办?
    【广州.NET社区线下活动】云定未来
    TDD/BDD和接口、基类、继承、依赖注入DI
    德国慕尼黑.NET俱乐部VS2019发布活动
    大湾区联动:广州深圳助力东莞.NET俱乐部首次线下活动
    .NET的未来-广州.NET俱乐部学生分会
    Belgrade Azure 2019-2-11活动感悟
    参观微软Serbia开发中心和Office365 2019-01-31活动感悟
    MySQL复制(二)--基于二进制日志文件(binlog)配置复制
    MySQL复制(一)--复制概述
  • 原文地址:https://www.cnblogs.com/lori/p/2151662.html
Copyright © 2011-2022 走看看