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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:24:17+00:00 2026-05-20T15:24:17+00:00

I have a problem and don’t know where to start as I am new

  • 0

I have a problem and don’t know where to start as I am new to MVC. I have three tables:

  • User (UserID, Username, etc…) This defines users.
  • Service (ServiceID, ServiceName, etc…) This defines services.
  • Licenses (ID, UserID, ServiceID, etc…) Maps services to a user.

In the back-end the user can access a service if he has a license. Ideally I would like a list of services in my EditUser view where I could check which services they should have licenses to.

This list needs to pre-populate with current licenses and if one is unchecked and saved it needs to be deleted.

I have all the methods to add and remove licenses, but I need to know how to implement this in my controller and view.

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-05-20T15:24:17+00:00Added an answer on May 20, 2026 at 3:24 pm

    First of all, define a ViewModel

    public class EditUserViewModel
    {
        public User User { get; set; }
        public IList<License> Licenses { get; set; }
        public IList<Service> Services { get; set; }
    }
    

    A View Model is simply a helper class that contains everything that you’ll need to display a view. Then, in your action:

    public ActionResult EditUser(int id)
    {
        var userViewModel = new EditUserViewModel
        {
            User = // Get user from db
            Licenses = // Get licenses for that user
            Services = // Getservies the user in entitled to   
        }
    
        return View(userViewModel); 
    }
    

    Then, make your view a typed view with EditUserViewModel for model:

    @model EditUserViewModel
    
    @* //Some html or whatever here *@
    
    @* //Access your model properties as follows *@
    @Model.User
    @Model.Licenses
    @Model.Service    
    

    You can reuse the EditUserViewModel class for other views, UserDetails, for instance. In that case you might want to rename and get rid of the “Edit” prefix.

    UPDATE to clarify question in comments:
    Rule of thumb: Keep your view models small, dumb and simple. No methods, functionality or intelligence, just a couple of properties that assist you in the display process. You’ll only want to reuse View Models on views that are very similar, like would be the case with an EditUser and DisplayUser view. You’d have a different view model for a DisplayServices view, etc.

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

Sidebar

Related Questions

I don't know where to look for about this problem ... I have three
I have this problem and don't know where to start. I need to write
I have a weird problem, and I don't know if this is the default
I have this problem and really don't know how to solve this. I'm having
I have a problem and don't know where it is... if I do this
I am pretty new in python, and I have a problem I don't know
I have this problem and I don't know what is the best solution for
I have problem and i don't know how to solve this simple, i have
I have this problem but I don't know how to name it, for instance,
I have a problem I don't know how to solve. I have an Indy10

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.