mvc 3 ,如何在视图。cshtml页面中用。cs文件中定义的变量?
cs文件中publicstaticreadonlyDictionary<string,string>OpenSelect=newDictionary<string,str...
cs文件中
public static readonly Dictionary<string, string> OpenSelect =
new Dictionary<string, string> {
{ "0", "非公开" },
{ "1", "公开" }
};
public static readonly Dictionary<string, string> StopOnSelect =
new Dictionary<string, string> {
{ "0", "継続" },
{ "1", "停止" }
};
在视图中如何应用
@Html.DropDownListFor(model => model.OpenFlag, OpenSelect, new { @class = "droplist-group" }) 展开
public static readonly Dictionary<string, string> OpenSelect =
new Dictionary<string, string> {
{ "0", "非公开" },
{ "1", "公开" }
};
public static readonly Dictionary<string, string> StopOnSelect =
new Dictionary<string, string> {
{ "0", "継続" },
{ "1", "停止" }
};
在视图中如何应用
@Html.DropDownListFor(model => model.OpenFlag, OpenSelect, new { @class = "droplist-group" }) 展开
3个回答
展开全部
//cs
ViewBag.你的定义的变量=你的代码;
//view
ViewBag.你的定义的变量;
追问
我想在视图中用OpenSelect 这个变量,直接用不可以的。也就是定义下拉框两个值
追答
//控制器代码
ViewBag.OpenSelect=new List<SelectListItem>()
{
new SelectListItem(){Text = "0", Value = "0"},
new SelectListItem(){Text = "1", Value = "1"}
};
//视图
@Html.DropDownListFor(model => model.OpenFlag, ViewBag.OpenSelect as IEnumerable<SelectListItem>, new { @class = "droplist-group" })
这样写出来应该没什么问题了吧!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询