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

  • Home
  • SEARCH
  • 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 8294123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:05:39+00:00 2026-06-08T14:05:39+00:00

Not sure if I’m completely missing something but, I have a typical MVC web

  • 0

Not sure if I’m completely missing something but, I have a typical MVC web application using EF and role based authentication, as such:

public class User
{
    public int UserId { get; set; }
    public string Name { get; set; }
    public IList<Role> UserRoles { get; set; }
}

public class Role
{
    public int RoleId { get; set; }
    public string Name { get; set; }
    public IList<User> RoleUsers { get; set; }
}

Ideally, in the above case, I would like a single edit screen to update a users name that also allows add/delete operations on the users roles, e.g. a form with an input field for the name, a table of the users roles with each row having a delete button, and a role drop down list with an add button.

How would I perform edits on the views model (User) without persisting the role additions/deletions to the database until a save request is issued?

It may be best to think of an Add operation instead. If inserting a new user, how could you build a collection of that users roles without inserting the user first?

Thanks in advance.

  • 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-08T14:05:41+00:00Added an answer on June 8, 2026 at 2:05 pm

    After looking into this a bit more, Phil Haacked wrote an article on binding a view model to a list, found here…

    http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

    I could probably have used this approach to have a single form with inputs for the entity properties and a collection of associated inputs bound using the above method for sub objects. Although I imagine this would probably require a duplicate list property for each navigation property on the parent entity, which is a strike for me.

    If adding an entity with a collection of complex objects, this method also doesn’t resolve how you might elegantly input all the properties for a complex object on the same view (as the parent entity only exists in memory) – the simplest approach probably being partial views containing the edit forms?

    For simplicity, I opted to change the edit view to only edit the basic properties of the entity and have a separate link for sub objects that redirects to the relevant controller, using the User example, an add operation would follow as such:

    • User/Edit/{user_id} view -> Input the users name, email etc.
    • Click Save -> Redirect to User/Index or User/Details/{user_id}
    • A ‘manage roles’ link is available for this user, once clicked -> Redirect to /Role/Index/{user_id}
    • Page displays a table of roles for this user with the ability to add/edit etc.

    Edit:

    Also, in case this helps anyone else.

    I set the /Role/Index action to list all roles by default, however it also accepts a UserId parameter (/Role/Index/{user_id}). When a UserId is specified, the action returns a different view (/Role/IndexForUser) whose data model is the User entity – it does the same as the default Index view, but only lists roles associated with the user, and displays more contextual links such as ‘remove user from role’.

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

Sidebar

Related Questions

not sure what i'm missing, but here ti go's: i have a floating left
Not sure if im just being stupid or something but here goes i work
Not sure how to ask this, but i'll give it a try: I have
not sure what I'm missing here, but i keep getting the error. SQLSTATE[HY093]: Invalid
Not sure what's going on here, but in my Rails 3 application, I type
Not sure what parallel programing means... but I have two thoughts of that Process
Not sure if this is possible but I have a slideshow on my site
Not sure if I worded this correctly ... but I have the following code:
Not sure if I can word this right but here we go. I have
Not sure if there's a better way to do this but I have a

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.