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)%>
  • 相关阅读:
    帮同事整理的 C# 调用 C++ 回调函数
    解决VS2010下使用NUnit 无法进行调试的问题
    Linux /var/log/messages 偶尔会发生time reset +6.288863s
    linux设置静态路由
    os auto installtion
    read 在bash ksh下的不同表现
    C#编码规范1
    C#中new一个对象时,发生了什么事?
    C# 实例化类的执行顺序
    C#类注释规范
  • 原文地址:https://www.cnblogs.com/lori/p/2151662.html
Copyright © 2011-2022 走看看