How to create sophisticated EditorTemplate in ASP.NET MVC 5 using db query?

I would like to create a more complex EditorTemplateone to select a client from the list.

I know DropDownListFor, but I would like to show cards with client images and some data is not only in the usual list select.

What I would like to do:

create EditorTemplateto select a client, for example ... In any POCO class

public class X{

    [Key] int Id {get;set;}

    [UIHint("CustomerSelector")] int Custumer_Id {get;set;}

}

And the editor template " CustomerSelector" can request all clients and display them in a list with rich names.

List of clients

What is the problem:

  • It is not recommended to add query logic from within the view. This contradicts the MVC pattern.
  • It is not very modular to request a list of clients in each controller and pass it as an EditorTemplate argument.

EditorTemplate MVC ?

+4
1

, - . , . MVC, , .

, , , . , , , .

, , - . . , , , . , - :

@Html.Action("CustomerSelect", new { fieldName = "Customer_Id" })

, , , , . , , - "MyCollection[" + i.ToString() + "].Customer_Id". , . .

- HtmlHelper. , , , , , , Razor.

+1

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


All Articles