vamp123
vamp123

Reputation: 57

What is the difference between an input model and a view model?

There are Domain model, View model and Input model. I am wondering what an Input model is. I'm completely confused, so what is this model?:

public class User{
    public string Name { get; set; }
    public string Age { get; set; }
}

View:

    @model EditFormApplication.Models.NewForm

    @using (Html.BeginForm("Index", "Home", FormMethod.Post))
    {
         @Html.TextBoxFor(model => model.Name)
         @Html.TextBoxFor(model => model.Age)
    <input type="submit" value="Save">
    }

Upvotes: 1

Views: 1088

Answers (2)

aspxsushil
aspxsushil

Reputation: 524

Data flow in and out of presentation layers

View Models usually populate the presentation layer. Any data that goes out of the presentation layer and triggers the back end can be considered the Input model. In most of the cases they usually coincide.

Domain Models are core models of your application domain. They mimic the real world objects of the domain. They contain business logic. As per DDD you could divide them into Entity and Value Objects. While architecting any application keeping your domain model Infrastructure agnostic is the key.It usually is the conceptual model of your business domain.

Upvotes: 0

Oscar W
Oscar W

Reputation: 484

The View model is what is passed into the view. Its values are then mapped onto the view for the user to see.

The Input model is the model used for collecting input from the user, and is posted back to the server, often times mapping to its equivalent View model

The Domain model is often the model that represents the corresponding data store that it belongs to.


In your case. The Input model User is what the html form will map the results to on postback.

So as we can see on these two lines

     @Html.TextBoxFor(model => model.Name)
     @Html.TextBoxFor(model => model.Age)

This will create a form with two text boxes, the first one corresponds to the User model's Name, and the second the Age

Upvotes: 4

Related Questions