Are binding domain models bad ideas?

I'm curious that binding models directly as parameters in an action method is considered a bad idea?

If the form becomes complex, I can create a custom binder.

Are there any pitfalls using this approach?

I would like to avoid creating a viewmodel because I want the application to be as simple as possible. I would like to avoid duplication of code and model for binding to the model.

+1
source share
3 answers

I would advise almost always to use representation models.

... - , , , . . , , ModelMetaData, ViewModel.

ViewModel, , , .

ViewModels , JsonResult... ... , ViewModels. JsonResult, ViewModel. , .

, , , ViewModel ( - , ), .

-, EF non-poco, .

, , ViewModels, .

, , , ViewModels.

+3

. - , , , ViewModel.

, DateTime, , DateTime, , string. , string .

, DropDown Model SelectListItem, .

.

+3

ViewModel. ( ). - :

public class DomainModelClass
{
    int Property1 { get; set; }
    int Property2 { get; set; }
}

public class ViewModelClass
{
    DomainModelClass DomainModel { get; set;}

    SelecList List1 { get; set; }
}

In any case, this proposal is just to make things simple, because I would advise you to create a β€œreal” view model and use something like AutoMapper to map ViewModel ↔ DomainModel even in a simple script.

+1
source

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


All Articles