Skip to main content
added 18 characters in body
Source Link

I like to take an MVVM style approach to MVC, for example, I use:

public class Person { }

as my domain model, and

public class PersonViewModel { }

as my view model. The view model is expressly used with the Controller and View. I also tend to use a mapping framework quite a lot, so I might mock up something like

public PersonController(IViewModelService<Person>IViewModelService<PersonViewModel> viewModelService)
{
    _viewModelService = viewModelService;
}

public ViewResult Edit(int id) 
{
    PersonViewModel model = _viewModelService.Get(id);
    return View(model);
}

[HttpPost]
public ViewResult Edit(PersonViewModel model)
{
    if (ModelState.Valid)
    {
        _viewModelService.Update(model);
    }

    return View(model);
}

where the IViewModelService<Person>IViewModelService<PersonViewModel> service is responsible for mapping my view model back to my domain model Person.

I like to take an MVVM style approach to MVC, for example, I use:

public class Person { }

as my domain model, and

public class PersonViewModel { }

as my view model. The view model is expressly used with the Controller and View. I also tend to use a mapping framework quite a lot, so I might mock up something like

public PersonController(IViewModelService<Person> viewModelService)
{
    _viewModelService = viewModelService;
}

public ViewResult Edit(int id) 
{
    PersonViewModel model = _viewModelService.Get(id);
    return View(model);
}

[HttpPost]
public ViewResult Edit(PersonViewModel model)
{
    if (ModelState.Valid)
    {
        _viewModelService.Update(model);
    }

    return View(model);
}

where the IViewModelService<Person> service is responsible for mapping my view model back to my domain model Person.

I like to take an MVVM style approach to MVC, for example, I use:

public class Person { }

as my domain model, and

public class PersonViewModel { }

as my view model. The view model is expressly used with the Controller and View. I also tend to use a mapping framework quite a lot, so I might mock up something like

public PersonController(IViewModelService<PersonViewModel> viewModelService)
{
    _viewModelService = viewModelService;
}

public ViewResult Edit(int id) 
{
    PersonViewModel model = _viewModelService.Get(id);
    return View(model);
}

[HttpPost]
public ViewResult Edit(PersonViewModel model)
{
    if (ModelState.Valid)
    {
        _viewModelService.Update(model);
    }

    return View(model);
}

where the IViewModelService<PersonViewModel> service is responsible for mapping my view model back to my domain model Person.

Source Link

I like to take an MVVM style approach to MVC, for example, I use:

public class Person { }

as my domain model, and

public class PersonViewModel { }

as my view model. The view model is expressly used with the Controller and View. I also tend to use a mapping framework quite a lot, so I might mock up something like

public PersonController(IViewModelService<Person> viewModelService)
{
    _viewModelService = viewModelService;
}

public ViewResult Edit(int id) 
{
    PersonViewModel model = _viewModelService.Get(id);
    return View(model);
}

[HttpPost]
public ViewResult Edit(PersonViewModel model)
{
    if (ModelState.Valid)
    {
        _viewModelService.Update(model);
    }

    return View(model);
}

where the IViewModelService<Person> service is responsible for mapping my view model back to my domain model Person.