Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7905601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:33:06+00:00 2026-06-03T10:33:06+00:00

I have three viewmodels to edit the same domain object. I use AutoMapper to

  • 0

I have three viewmodels to edit the same domain object.
I use AutoMapper to map to viewmodels from the domain object.

GET

if (Roles.IsUserInRole("administrators"))
{
    viewName = "EditAdmin";
    editOrder = Mapper.Map<Order, ViewModels.Order.Admin_ViewModel>(order);
}
else if (Roles.IsUserInRole("administrators"))
{
    viewName = "EditTechnician";
    editOrder = Mapper.Map<Order, ViewModels.Order.Technician_ViewModel>(order);
}
else if (Roles.IsUserInRole("clients"))
{
    viewName = "EditClient";
    editOrder = Mapper.Map<Order, ViewModels.Order.Client_ViewModel>(order);
}

RedirectToRoute(viewName, editOrder);

POST
Is it possible to use the same method for all viewmodels?
Possibly by letting the ViewModels inherit from “ViewModelbase”?
Tried this with no success 🙁

Many thanks in advance!

EDIT:
This is what my method looks like now:

public ActionResult EditAdmin(ViewModels.Order.Admin_ViewModel model) {...}

Any ideas?

UPDATE:
I wasn’t able to understand how to use composition (tried it for a few hours). So I went with this to clean up a bit. These are the handlers for my three viewmodels:

[HttpPost]
[Authorize(Roles = "administrators")]
public ActionResult EditAdmin(Admin_ViewModel model)
{
    return SaveViewModel(model);
}

[HttpPost]
[Authorize(Roles = "technicians")]
public ActionResult EditTechnician(Technician_ViewModel model)
{
    return SaveViewModel(model);
}

[HttpPost]
[Authorize(Roles = "clients")]
public ActionResult EditClient(Client_ViewModel model)
{
    return SaveViewModel(model);
}

SaveViewModel looks like this:

protected ActionResult SaveViewModel(dynamic model)
{ ... }

I don’t feel to good about this solution. Could you please give me some pointers?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:33:08+00:00Added an answer on June 3, 2026 at 10:33 am

    IMHO – ViewModel should plain and simple. If you introduce inheritance, it is going get complicated.

    I suggest you to use composition to build the ViewModel you want. So if the user is in a particular role, objects which are not related to the Role will be null when the page is posted. With that you can stick to one POST method rather than many.

    Update :
    If you really want to have the inheritance in ViewModel. Custom model binder is the solution, if the default one is not working

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection of ViewModels that I send back to from controller to
recently i've started to use viewmodels with automapper. the problem appeared immediately. for example,
Have three classes User, Group and Field. Many to many relationship on User /
Have three divs in a container that I want to float over a large
I have three tables A: A.pID primary key, A.Name nvarchar(250) B: B.pID primary key,
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have three column in my datagridview .One is text ,one is Combo and
I have three computers on my LAN, one running ubuntu , one running openSuse
I have three files: one called sql.php witch has a class db that I
I have three tabs. When I press the tab button on the bottom, is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.