0
点赞
收藏
分享

微信扫一扫

在MVC中Controller为VIEW页面中的DropDownList赋值并锁定

首先是枚举对象的遍历


#region

new

foreach (string i in Enum.GetNames(typeof(ServiceDocumentType)))

{

newtypeof(ServiceDocumentType), i)).GetDescription(), int)((ServiceDocumentType)typeof(ServiceDocumentType), i))).ToString() });

}

#endregion

当有了上面基础后,再根据传入到当前实体,锁定当然选中的项

new

{

ProductID = entity.ProductID,

Content = entity.Content,

DownloadUrl = entity.DownloadUrl,

ImageUrl = entity.ImageUrl,

Level = entity.Level,

LinkUrl = entity.LinkUrl,

Title = entity.Title,

new SelectList(typeitems, "Value", "Text", (int)entity.Type),

new SelectList(statusItems, "Value", "Text", (int)entity.Status),

};

其中Type和Status都是SelectList类型,这样方便前台Model在VIEW中的展示。

前台中展示就一句搞定:


"Type",Model.Type)%>


作者:仓储大叔,张占岭,
荣誉:微软MVP

在MVC中Controller为VIEW页面中的DropDownList赋值并锁定_html



举报

相关推荐

0 条评论