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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:43:27+00:00 2026-06-15T21:43:27+00:00

My context is: public class RegistrationManagerContext : DbContext { public DbSet<User> Users { get;

  • 0

My context is:

public class RegistrationManagerContext : DbContext
{
    public DbSet<User> Users { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<User>()                
            .ToTable("aspnet_Users");
    }
}

and my User class is:

[Table("aspnet_Users")]
public class User
{
    [Key]
    [Display(AutoGenerateField = true)]
    [Required]
    public Guid UserId { get; set; }

    [DataType("nvarchar")]
    [MaxLength(256)]
    [Required]
    public string UserName { get; set; }

    [DisplayFormat(ApplyFormatInEditMode = true, ConvertEmptyStringToNull = true, DataFormatString = "{0:d}")]
    [Required]
    public DateTime LastActivityDate { get; set; }

    [NotMapped]
    public AccountProfile Profile
    { 
        get 
        { 
            if (_profile == null)
            {
                _profile = AccountProfile.GetUserProfile(this.UserName);
            }
            return _profile;
        }
    }
    private AccountProfile _profile = null;
}

and my call method (Controller) is:

namespace RegistrationManager.Controllers
{

    [Authorize(Roles="Admins")]
    public class AdminController : Controller
    {

        private RegistrationManagerContext db = new RegistrationManagerContext();

        //
        // GET: /Admin/

        public ActionResult Index(int? id)
        {
            var viewModel = db.Users;
            if (id.HasValue)
            {
                ViewBag.UserID = id.Value;
            }
            return View(viewModel);
        }

    }
}

My view is:

@model IEnumerable<RegistrationManager.Models.User>

@{
        ViewBag.Title = "Users";
}

<h2>Users</h2>


<table>
    <tr>
        <th>Email Address</th>
        <th>Given Names</th>
        <th>Surname</th>
        <th>Last Ac</th>
        <th>Refresh</th>
    </tr>

@foreach (var item in Model)
{
    string selectedRow = "";
    if (ViewBag.UserId != null && item.UserId == ViewBag.UserId)  
    {  
        selectedRow = "selectedrow";  
    }  
    <tr class="@selectedRow" valign="top">
        <td>
            @item.UserName
        </td>
        <td>
            @item.Profile.GivenNames
        </td>
        <td>
            @item.Profile.Surname
        </td>
        <td>
            @String.Format("{0:d}", item.LastActivityDate)
        </td>
        <td>
            @Html.ActionLink("Refresh", "Refresh", "Admin", new { id = item.UserId }) 
        </td>
    </tr>
}
</table>

So what am I doing wrong or what am I missing?? As I get no data!!?? There is definitely data as I should at least see my own login, right!?

  • 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-15T21:43:28+00:00Added an answer on June 15, 2026 at 9:43 pm

    Shouldn’t you be doing something like this:

        public ActionResult Index(Guid? id)
        {
            if (id.HasValue)
            {
                var viewModel = db.Users.Where(x=>x.UserId == id.Value).FirstOrDefault();
                //ViewBag.UserID = id.Value; //You do not need it here
                if(viewModel != null)
                      return View(viewModel);
            }
            return RedirectToAction("UsersListPage");
        }
    

    UPDATE #1

    Controller:

        public ViewResult Index(){
               return View(db.Users.ToList());
        }
    

    View:

        @model IEnumerable<YourNamespace.User>
    
        @foreach (var user in Model) {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => user.UserName)
            </td>            
        </tr>
         }
    

    Isn’t this working for you?

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

Sidebar

Related Questions

public class SomeRepository<TContext> : IDisposable where TContext : DbContext, new() { protected TContext context;
Some code for context: class a { } class b { public a a{get;set;}
public class UploadHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { ... // Create
class classe (){ public: int key; static void *funct(void *context){ printf(Output: %d, , key);
My model: public partial class history_builds { public int ID { get; set; }
Relevant Code Snippet: public class MyPreference extends Preference { public MyPreference(Context context, AttributeSet attrs)
CustomExceptionHandler public class CustomExceptionHandler implements UncaughtExceptionHandler { private Context ctx; private ContentResolver cr; public
`Adapter class ::: public class YAdapter extends ArrayAdapter<String> { ArrayList<String> items; Context context; private
I have the following test case: @ContextConfiguration(/spring/test-context.xml) @TransactionConfiguration(transactionManager=txManager) @Transactional() public class MyEntityDaoTestCase extends AbstractJUnit4SpringContextTests
I have a class like this: public class Contest { List<ContestTeam> Teams { 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.