编辑模板的名单,LT;字符串> [英] Editor Templates for List<string>

查看:137
本文介绍了编辑模板的名单,LT;字符串>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待创造我的ASP.NET MVC3网站的一些基本款的通用编辑器。现在,他们可以包含字符串,布尔,枚举和列表集合。我想要做的就是扩展默认的编辑器模板来识别列表和显示自定义编辑器,可以添加和删除字符串列表中。所有的人工作得很好。

I am looking to create a generic editor for some basic models in my ASP.NET MVC3 site. Now they can contain strings, booleans, enums and List collections. What I want to do is extend the default editor templates to recognise List and show a custom editor which can add and remove strings to this list. All the others work just fine.

由于我不能命名该文件当然List.cshtml有没有一种办法能够得到这个工作?另外,为什么不枚举默认情况下,下拉枚举的列表?

As I cannot name the file List.cshtml of course Is there a way to be able to get this to work? Also why are enums not drop down lists of the enum by default?

我知道我可以创建命名模板模型,但我不知道类名,直到运行时。

I know I can create model named templates but I do not know the class names until runtime.

感谢您的帮助和指导。

推荐答案

您可以命名编辑模板 Foo.cshtml ,其中是列表的类型:列表<富> 。然后简单:

You can name the editor template Foo.cshtml where Foo is the type of the list: List<Foo>. Then simply:

@Html.EditorFor(x => x.FooList)

如果 FooList 的IEnumerable&LT;富&GT; 你的编辑模板将自动呈现的这每一个元素名单。所以,如果你已经有编辑模板的基本数据类型,如字符串,小数,日期时间,...当你做 @ Html.EditorFor(X =&GT; x.SomeList)你的编辑模板将有所回升。

and if FooList is an IEnumerable<Foo> your editor template will be automatically rendered for each element of this list. So if you already have editor templates for the basic data types such as String, Decimal, DateTime, ... when you do @Html.EditorFor(x => x.SomeList) your editor templates will be picked up.

这篇关于编辑模板的名单,LT;字符串&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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