如何使用ienumerable< model>填充HTML帮助器下拉列表或下拉列表 [英] How to populate HTML helper dropdownlist or dropdownlistfor with ienumerable<model>

查看:125
本文介绍了如何使用ienumerable< model>填充HTML帮助器下拉列表或下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IEnumerable< model>模型绑定到我的视图,模型包含所有普通值。没有IEnumerable<>模型中的值。我需要使用此模型中的值填充一些DropDownList或DropDownListFor。有没有办法可以使用模型属性填充DropDownList,而无需使用我的操作方法。这是我的模特:



@model IEnumerable< kesp.tbl_monitoring>

我的行动方法返回值为:



返回查看(db.tbl_Monitoring.ToList());

任何人都可以帮助我,我被困住并且从几小时开始搜索,但找不到任何解决方案



我尝试过:



尝试了太多选项但是没有为我工作

I have an IEnumerable<model> model bound to my view and the model contains all plain values. There is no IEnumerable<> value in the model. I need to populate some DropDownList or DropDownListFor with the values from this model. Is there a way that I could populate DropDownList with model property without working in my action method. Here is my model:

@model IEnumerable<kesp.tbl_monitoring>
and my action method is returning value as:

return View(db.tbl_Monitoring.ToList());
Can any one help me, I am stuck and searching from hours, but could not found any solution

What I have tried:

Tried too many options but did not worked for me

推荐答案

@Html.DropDownList("Distric", new SelectList(Model.Select(k => k.Distric)), "Select Distric");


这篇关于如何使用ienumerable&lt; model&gt;填充HTML帮助器下拉列表或下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆