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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:32:59+00:00 2026-06-09T19:32:59+00:00

I have my model for my users in MVC3: public class User { [Key]

  • 0

I have my model for my users in MVC3:

public class User
{
    [Key]
    public virtual Guid UserId { get; set; }

    [Required]
    public virtual String Username { get; set; }

    [DataType(DataType.MultilineText)]
    public virtual String Comment { get; set; }

   ..loads of other properties

This class contains loads of info that I don’t really need in an edit screen. Let’s say I only wanted to edit the comment part of the user. I tried to create a viewmodel like this but not sure if im going about this right

view model

 public class UserViewModel
  {
    public string notes;

  }

Now I have this in my controller:

public ActionResult Edit(Guid id)
        {
           User user = Context.Users.Where(x => x.UserId == id).First();
          UserViewModel uvm = new UserViewModel();
          uvm.notes = user.Comment;
            return View(uvm);
        }

This part seems to work ok and passes the info through if it exists.
The edit view is like this:

@model core.Areas.Manage.Models.UserViewModel
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>User Edit</legend>

        @Html.TextBoxFor(model => model.notes)


        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
}

Which shows the notes/comment from the controller.
However, if i press submit, the model is nulled – The model.notes is null at this point:

 [HttpPost]
        public ActionResult Edit(Guid id, UserViewModel model)
        {

Am i doing something completely wrong? In the past I simply passed the whole model around, but this isn’t really ideal.
Im kind of taking a stab in the dark here, just thought i’d try to implement it myself before turning to SO!

  • 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-09T19:33:00+00:00Added an answer on June 9, 2026 at 7:33 pm

    I think it might be because you don’t have {get;set;} declared in your view model. See this post: { get; set; } used in ViewModel

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

Sidebar

Related Questions

I have a model like this: class Users(db.Model): email = db.EmailProperty(required=True, indexed=True) user_name =
I have these models: class UserProfile(models.Model): user = models.OneToOneField(User) #etc class Organization(models.Model): users =
I have the following model entity: public class ScheduledTask { public virtual int ScheduledTaskId
I have this code App.Model('users').find(function (err, users) { users.forEach(function(user) { console.log(user.username); }); }); //make
I have a model called company that has_many users then users belongs_to company. class
For instance, let's say I have a User model. Users have things like logins,
User is a model. I have 100 users. I need to present the list
I have a question about ASP.NET MVC3 model binding. If I have a class
I have two model class in MVC3 one for Services which have those properties
I have the following class... public class Product { public int Id { get;

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.