If I have a ViewModel like this:
public class MyViewModel { [UIHint("SomeTemplate")] public ICollection<SomeViewModel> Submodel { get; set; } }
And a strongly typed View with an HTML line as follows:
@Html.DisplayFor(model => model.Submodel)
And a display template with this signature:
@model MvcApplication1.Models.SomeViewModel
I get an error: "The model element is of type List<SomeViewModel> , but this dictionary requires a model of type SomeViewModel .".
Which makes sense, but I would hope that the built-in sms MVC templates will start working, look at this IEnumerable something and work out to call my template N times, for example, as is usually done for Html.DisplayFor .
So it looks like [UIHint] redefining this functionality?
Obviously, I can point to another template that accepts the collection and call Html.DisplayForModel() , mostly mimicking MVC emoticons. But I hope to avoid this. Honestly, I'd rather have a foreach loop than having this 1-line wrapper pattern.
Any better ideas?
I like what I want to say: "Hi MVC, output a template for each of these guys. But instead of using the naming convention to find the template, here is a hint."
asp.net-mvc asp.net-mvc-3 razor data-annotations
RPM1984
source share