IDictionary的要选择列表? [英] IDictionary to SelectList?

查看:143
本文介绍了IDictionary的要选择列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个IDictionary,现在我想在选择列表中使用这些值。如何做到这一点?

I have an IDictionary, now I want to use these values in a selectlist. How do I do this?

感谢。

推荐答案

刚刚成立 dataValueField dataTextField 。你可以做到这一点在你查看自己或你的动作(没有测试code以下)。

Just set "Value" and "Key" for dataValueField and dataTextField. You can either do this in your View itself or from your action (haven't tested the code below).


var targets = new Dictionary<string, string>();
targets.Add("Key", "Value");

ViewData["MyList"] = new SelectList(targets, "Key", "Value");

这篇关于IDictionary的要选择列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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