Reputation: 11069
Without using "UIHint" how to create .cshtml for certain types of data.
[DataType(DataType.Url)]
public string Link { get; set; }
will be used
Url.cshtml
[DataType(DataType.MultilineText)]
public string Descrition { get; set; }
will be used
MultilineText.cshtml
public IEnumerable<SelectListItem> TypesList { get; set; }
will be used
???????????.cshtml
public DateTime? DateUpdated { get; set; }
will be used
???????????.cshtml
public int? Order { get; set; }
will be used
???????????.cshtml
In short, do not want to be putting in my ViewModel attributes, like that would work exactly like "Url" and "Multiline"
What should be the file name .cshtml
that will be used to int?
, IEnumerable<xx>
or IEnumerable<string>
Remembering that you can not create files with "<", ">" or "?"
Upvotes: 0
Views: 2262
Reputation: 1039318
By convention (if you don't specify any template name):
public IEnumerable<SelectListItem> TypesList { get; set; }
will use SelectListItem.cshtml
(not that since you have an IEnumerable<T>
the editor template will be rendered for each element of the collection and will be called T.cshtml
)public DateTime? DateUpdated { get; set; }
will use DateTime.cshtml
public int? Order { get; set; }
will use Int32.cshtml
...You could also specify a template name in the view:
@Html.EditorFor(x => x.TypesList, "MyTemplate.cshtml")
Assuming TypesList
is an IEnumerable<T>
then MyTemplate.cshtml
will be strongly typed to IEnumerable<T>
and not to T
.
Upvotes: 4