I still hesitate to use ViewModels instead of Model for the View

Wether I use Automapper or manual matching, which does not play any role.

All data for ReleaseViewModel must be the first in Release because it is filled with a data access layer. 90% of my model is like that. Why does overhead duplicate everything?

What about the KISS principle and add-ons?

Of course, every tool is for its respective task, but very often I read on SO that not using ViewModels in asp.net mvc is NO-GO.

Where to draw a line? Should I use ViewModels when they differ from 50%, 75% or 99% from my models?

I have a Release model:

 public class Release
    {      
        public int Id { get; set; }       
        public string Name { get; set; }
        public string Author { get; set; }
        public DateTime CreatedAt { get; set; }
        public int FailedTestsCount { get; set; }
        public int SucceededTestsCount { get; set; }
        public int SumTestsCount
        {
            get
            {
                return SucceededTestsCount + FailedTestsCount;
            }
        }
        public int SumTestingTime { get; set; }
    }

a viewmodel ReleaseViewModel:

public class ReleaseViewModel
{
    [HiddenInput(DisplayValue = false)]
    public int Id { get; set; }

    [Required(ErrorMessage = "Name must not be empty.")]
    [StringLength(30, ErrorMessage = "Enter max. 30 chars for a name.")]
    [Remote("ReleaseExists", "Release", ErrorMessage = "This name already exists.")]
    public string Name { get; set; }    
    public string Author { get; set; }    
    public DateTime CreatedAt { get; set; }    
    public int FailedTestsCount { get; set; }    
    public int SucceededTestsCount { get; set; }    
    public int SumTestsCount 
    {
        get
        {
            return SucceededTestsCount + FailedTestsCount;
        }
    }

    public int SumTestingTime { get; set; }
}
+5
source share
5 answers

ViewModel - -, VIEW. . .

. ViewModel Remote Attribute Validation. , - , , . .

, Viewmodel, , . . User Entity Project Entity, , . , viewmodel

public class ProjectToUserVM
{
  public int UserId { set;get;}
  public string UserName { set;get;}  // i want to display only name of user!
  public int ProjectID { set;get;}
  public IEnumerable<SelectListItem> Projects { set;get}
}

ViewModels . , . Model , viewmodel, . : // (. . /)

+5

?

, , , , , ,

, , , : SRP ( )

, , , , , . .

MVC , , , . . ( CQRS, )

CQRS ( , , , ), , ( )

, KISS, YAGNI, ,

, = (, , , - , , SRP

+2

My ViewModels 90% . , - . , , (, , ).

, IoC, Castle SpringFramework.net, " ", , . " ", , .

+1

-, , Shyju, " ".

, EntityModel , ViewModel, ViewModel dto . , - : " , , dumass". , . .

EntityModels -- - , DLL - . , , RemoteAttribute HiddenInputAttribute . viewmodel dto System.Web.Mvc.dll EntityModel, .

, , EntityModel - ( , ), - - . - /, , , , , , .

0

Release INotifyPropertyChanged , (, ,...), viewmodel. ...

0

All Articles