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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:17:31+00:00 2026-05-12T10:17:31+00:00

I have a model that looks like this: public class UserAdminEditViewModel { public User

  • 0

I have a model that looks like this:

public class UserAdminEditViewModel
{
    public User User { get; set; }
    public IEnumerable<Usergroup> Usergroups { get; set; }
    public IList<int> UsergroupID { get; set; }

    public UserAdminEditViewModel() {}
}

And my View looks like this:

” %>
UserEdit

UserEdit

<% using (Html.BeginForm()) {%>

    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="Username">Användarnamn: *</label>
            <%= Html.TextBox("Username", Model.User.Username) %>
            <%= Html.ValidationMessage("Username", "*") %>
        </p>
        <p>
            <label for="Firstname">Förnamn: *</label>
            <%= Html.TextBox("Firstname", Model.User.Firstname) %>
            <%= Html.ValidationMessage("Firstname", "*") %>
        </p>
        <p>
            <label for="Surname">Efternamn: *</label>
            <%= Html.TextBox("Surname", Model.User.Surname) %>
            <%= Html.ValidationMessage("Surname", "*") %>
        </p>
        <p>
            <label for="Email">E-post: *</label>
            <%= Html.TextBox("Email", Model.User.Email) %>
            <%= Html.ValidationMessage("Email", "*") %>
        </p>
        <p>
            <label for="Password">Lösenord: *</label>
            <%= Html.TextBox("Password", Model.User.Password) %>
            <%= Html.ValidationMessage("Password", "*") %>
        </p>
        <p>
            Användargrupper: <br />
            <%= Html.CheckBoxList(Model.Usergroups.Select(ug => ug.UsergroupID.ToString()), Model.Usergroups.Select(ug => ug.UsergroupName), "UsergroupID") %>
        </p>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>

<% } %>

<div>
    <%=Html.ActionLink("Tillbaka till användare", "Users") %>
</div>

My controller looks like:

public ActionResult UserEdit(int? userID)
    {
        User u;

        if (userID == null)
        {
            u = new User();
        }
        else
        {
            u = us.GetUsers(userID.Value).SingleOrDefault();
        }



        return View("UserEdit", new UserAdminEditViewModel { User = u, Usergroups = ug.GetUsergroups() });
    }


    [AcceptVerbs(HttpVerbs.Post)]
    //public ActionResult UserEdit([BindAttribute(Include = "Firstname,Surname,Username,Email,Password,UserID,UsergroupID")]User userobj, IList<int> UsergroupID)
    public ActionResult UserEdit(UserAdminEditViewModel userobj)
    {
        if (ModelState.IsValid)
        {
            try
            {

                //userobj.UsersUsergroups = new UsersUsergroup { UsergroupID = UsergroupID.ToList() };

                //us.SaveUser(userobj);
            }
            catch
            {
                ModelState.AddModelError("SomeError", "errrrrrrrrror");
            }
        }

        return View();
        //return View("UserDetail", new UserAdminEditViewModel { User = userobj });
    }

Problem:

If I use the UserAdminEditViewModel I created, only values for IList UsergroupID gets set (which is a list of checkboxes named UsergroupID). If I use the User class I can access all the user properties as firstname etc gets filled in.

Why doesnt the User object get populated in the UserAdminEditViewModel on post? Whats missing?

Thanks in advance
/M

EDIT:

View is strongly typed to “BookingSystem.MVC.ViewModels.UserAdminEditViewModel”

can’t make it show in this editor

  • 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-12T10:17:32+00:00Added an answer on May 12, 2026 at 10:17 am

    use

    <%= Html.TextBox("User.Firstname", Model.User.Firstname) %>
    

    . Check in the rendered view. The Formfields should render:

     <input  type="text" name="User.Firstname" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 188k
  • Answers 188k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Minutes are already a usable form of number for a… May 12, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer You are essentially right. There is nothing really wrong with… May 12, 2026 at 5:32 pm
  • Editorial Team
    Editorial Team added an answer ATTEMPT 3 - I swear last one... I believe this… May 12, 2026 at 5:32 pm

Related Questions

Let's say that you have a Model that looks kind of like this: public
I have a class in my domain model root that looks like this: namespace
I've been adding xVal to the NerdDinner app - so far so good, I
I have a C module which is created by the Real-time Workshop based on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.