English 中文(简体)
• 投影机,安装ICollection<string>。 NET MVC3 View?
原标题:Trying to use EditorFor with an ICollection<string> in an ASP.NET MVC3 View?

I m 试图在Create的情形下展示一个类别物体,即一个财产为 ICollection<string>

For example...

namespace StackOverflow.Entities
{
    public class Question
    {
        public int Id { get; set; }
        ....
        public ICollection<string> Tags { get; set; }
    }
}

如果这种观点与StackOverflow一样,请问一页,Tagshtml is a one input Box 。 我不敢肯定我如何能够在伙伴关系中这样做。 NET MVC3 的观点

任何想法?

我尝试使用<代码>EditorFor,但在浏览器上没有显示任何东西,因为它无法确定如何收集插图。

最佳回答

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.uihintattute.aspx” rel=“noreferer”。 属性:

public class Question
{
    public int Id { get; set; }

    [UIHint("tags")]
    public ICollection<string> Tags { get; set; }
}

之后,主要考虑:

@model StackOverflow.Entities.Question
@Html.EditorFor(x => x.Tags)

之后,您可以撰写一个定制编辑模板(~/Views/joint/EditorTemplates/tags.cshtml):

@model ICollection<string>
@Html.TextBox("", string.Join(",", Model))

或者,如果你不喜欢装饰,你还可以具体说明编辑模板,直接用于特定财产:

@model StackOverflow.Entities.Question
@Html.EditorFor(x => x.Tags, "tags")
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...