ASP.NET MVC mapping template for generic type

I am trying to use the ListModel model as a generic list model. I would like to enter the page

@Html.DisplayForModel()

However, MVC does not find the template file "ListModel.cshtml" correctly. It should work differently for general models. What should I name a template file so that it can be positioned correctly?

public class ListModel<T>
{
public IEnumerable<T> Models { get; set; }
public string NextPage { get; set; }
}

I expect him to look Shared/DisplayTemplates/ListModel.ascx, but it is not. Somebody knows?

Edit:

In the end, I decided to solve this by simply deleting such a common parameter. I really want to know if you still have a common file name.

public class ListModel
{
    public IEnumerable Models {get;set;}
    public string NextPage {get;set;}
}
+3
source share
3 answers

, ListModel<T> UIHint, , ?

,

[UIHint("ListModel")]
public class ListModel<T>
{
...
+1

, .

: - (, ListModel`1.ascx - ), MVC - ? / ?

, MS , , , .

, , .

+1

, MVC .

@Html.DisplayForModel("ListModel")

@Html.DisplayFor(m=>m.AProperty,"TemplateName")
0

Source: https://habr.com/ru/post/1782122/


All Articles