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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:52:50+00:00 2026-06-02T07:52:50+00:00

This is my model public class AdministrationModel { public string FirstName { get; set;

  • 0

This is my model

public class AdministrationModel
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string EmailAddress { get; set; }
  public bool IsApproved { get; set; }
}

This is my controller

public ActionResult GetTabContent(string id)
{
  switch (id)
  {
   case "tab3":
   model = GetAllUsersInfo();
   viewName = "Administration";
   break;
   }
   return View(viewName);
 }

  private List<AdministrationModel> GetAllUsersInfo()
  {
    List<AdministrationModel> userList = new List<AdministrationModel>();
    foreach (MembershipUser user in Membership.GetAllUsers())
    {
      UserProfile userProfile = UserProfile.GetUserProfile(user.UserName);
      userList.Add(new AdministrationModel { EmailAddress = user.Email,                       IsApproved = user.IsApproved, FirstName = userProfile.FirstName, LastName = userProfile.LastName });
    }

    return userList;
  }

This is my View

@model List<AdminContainerModel>
@using (Html.BeginForm("Administration", "Account"))
{
  <fieldset>
    <div>
      @foreach (AdministrationModel AM in Model)
      {
        <div>
         <div class="colFull">@Html.DisplayFor(modelItem => AM.FirstName)</div>
         <div class="colFull">@Html.DisplayFor(modelItem => AM.LastName)</div>
         <div class="colFull">@Html.DisplayFor(modelItem => AM.EmailAddress)</div>
         <div class="colPartial"><input type="checkbox" checked="@AM.IsApproved"/>            </div>
      <div class="clear"></div>
    </div>
  }
</div>
 <input type="submit" value="Update Account" />
 </fieldset>
}

When the user clicks the Update Account button it goes to the controller

  [HttpPost]
  public ActionResult Administration(List<AdministrationModel> model)
  {
     return View();
  }

inside this method, model is always null. however the View that renders everything is perfect and shows what I want it to show. What am I doing wrong?

  • 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-02T07:52:52+00:00Added an answer on June 2, 2026 at 7:52 am

    When using collections, in order to correctly process them so they are model-bound on post without any additional leg work, you need to make sure they are indexed correctly, you can do this by using a for loop, something like:

    @for (int i = 0; i < Model.Count; i++)
    {
        @Html.HiddenFor(m => m[i].FirstName)
        @Html.HiddenFor(m => m[i].LastName)
        @Html.HiddenFor(m => m[i].EmailAddress)
        <div>
            <div class="colFull">@Html.DisplayFor(m => m[i].FirstName)</div>
            <div class="colFull">@Html.DisplayFor(m => m[i].LastName)</div>
            <div class="colFull">@Html.DisplayFor(m => m[i].EmailAddress)</div>
            <div class="colPartial">@Html.CheckBoxFor(m => m[i].IsApproved)</div>
            <div class="clear"></div>
        </div>
    }
    

    That should model bind without any other code 🙂

    Edit: Sorry I forgot, displayFors by default don’t put the correct properties on for model binding, added hiddenFors for the other fields that don’t have an editorFor

    Edit2: Based on your other question in the comment, if it was public facing and you didn’t want them to change any of the hidden for values using the dev tools, try the following:

    Ok so you don’t want them to change the hiddenFors, that’s fine, but you will need some sort of ID so you know which client is which when the data is posted, I suggest that instead of having these in the above code:

    @Html.HiddenFor(m => m[i].FirstName)
    @Html.HiddenFor(m => m[i].LastName)
    @Html.HiddenFor(m => m[i].EmailAddress)
    

    Replace them with:

    @Html.HiddenFor(m => m[i].ClientId)
    

    That way you’re not posting back the firstname, lastname or email address, just a reference to the actual client that is ticked, unticked.

    To answer your other question in the comment about keeping track of the original values, in your controller method you can just go and get the original values from the database, then here’s how you can detect which ones are different, something like:

    [HttpPost]
    public ActionResult Administration(List<AdministrationModel> model)
    {
        var originalMatches = GetAllUsersInfo();
    
        var differences = (from o in originalMatches
                          join c in model on o.ClientId equals c.ClientId
                          where c.IsApproved != o.IsApproved).ToList()
    
        return View();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this model: public class Package { public string CustomerName { get; set;
If this is my view model: public class ViewModel{ public string SimpleProperty{get;set;} public SubViewModel
Take this example model: public class Location { public string Id { get; set;
So I have this model setup public class ListOfThings { public int Id {get;set;}
I created this class: public class PageMeta { public string User { get; set;
My Model: public class EntryModel { [Required] public string Date { get; set; }
I have this model : public class Person { public string Name { get;
I have this model: public class SearchModel { [DefaultValue(true)] public bool IsMale { get;
I have this model: public class ExchangeRate { [Key] public int ExchangeRateID { get;
Given domain model... public class Entity { public int Id { get; set; }

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.