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 5931703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:43:55+00:00 2026-05-22T14:43:55+00:00

For each entity in my repository, I have a view model and an input

  • 0

For each entity in my repository, I have a view model and an input model. I find having an input model to store relational IDs (as opposed to foreign entities) makes rendering select lists easier, but which model do you pass to your Edit view for rendering, View Model or Input Model?

Sample POST action for Category entity:

[HttpPost]
public ActionResult Edit(CategoryInputModel inputModel)
{
    // map inputModel to entity and persist
    // ...
}

View Model:

[HttpGet]
public ActionResult Edit(int id)
{
    var category = _unitOfWork.CurrentSession.Get<Category>(id);
    var viewModel = Mapper.Map<Category, CategoryViewModel>(category);
    return View(viewModel);
}

In this case the edit view form would take care of providing the correct input model fields for the POST action.

Input Model:

[HttpGet]
public ActionResult Edit(int id)
{
    var category = _unitOfWork.CurrentSession.Get<Category>(id);
    var inputModel = Mapper.Map<Category, CategoryInputModel>(category);
    return View(inputModel);
}

Which is easier to maintain in the long run?

  • 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-05-22T14:43:55+00:00Added an answer on May 22, 2026 at 2:43 pm

    I’m now using an input model that does not contain an ID. I keep the entity ID as the action parameter, like so:

    [HttpPost]
    public ActionResult Edit(Guid id, CategoryInputModel inputModel)
    {
        var category = _categoryRepository.Get(id);
        // do mappings from inputModel to category and save
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a repository for basically each entity but my model has a
Basically each entity would have a collection of feeding behaviors that it would follow.
How to implement objects (entities) cloning in NHibernate? Each entity class has such properties:
Say I have an parent entity, each of which have a number of children.
I have a product entity which has several classes (each product type has different
I have implemented a simple repository pattern for the Entity Framework in a web
I'm using Entity Framework Code First and whilst I have working code, I'm having
I have my Database , that have my ADO.NET Entity Data Model that have
Each of my clients can have many todo items and every todo item has
Each item in a WPF ListBox control seems to have a bit of left

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.