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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:57:16+00:00 2026-05-30T20:57:16+00:00

I have a scenario where I create Machine entities that are associated with the

  • 0

I have a scenario where I create “Machine” entities that are associated with the logged in user (windows authentication) that created them. The user is only ever created in the database once they have created at least one Machine entity.

I’m using model binding on the create Machine form. The Machine model has an associated User entity, a custom one that looks like this:

public class User
{
    public int UserId { get; set; }

    [DisplayName("User")]
    public string Username { get; set; }

    public string Email { get; set; }

    public int SectorId { get; set; }
    public Sector Sector { get; set; }

    public List<Machine> Machines { get; set; }
}

So far, in the create machine view I have created a hidden input for the user name using the following:

@Html.HiddenFor(model => model.User.Username, new { User.Identity.Name })

But I’m finding that this is not populated in the model when it is returned to the HttpPost create handler.

I was wondering how I might be able to pass the username down with the model?

  • 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-30T20:57:18+00:00Added an answer on May 30, 2026 at 8:57 pm

    First off, the problem you’re having with your HiddenFor() method call is that the second parameter is supposed to be an object for htmlAttributes. So your method call isn’t correct. (MSDN Reference for the HiddenFor() method):

    public static MvcHtmlString HiddenFor<TModel, TProperty>(
        this HtmlHelper<TModel> htmlHelper,
        Expression<Func<TModel, TProperty>> expression,
        Object htmlAttributes
    )
    

    Why are you trying to populate this within the View? Take this logic to the controller:

    [HttpPost]
    public ActionResult GetUser(User newUser)
    {
        newUser.UserName = User.Identity.Name;
    
        // now do something with the passed in model
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is a scenario: User installs .NET application that you have made. After some
I have the following scenario, I want to create a DataGrid and then populate
Here's the scenario: I have 2 tables: CREATE TABLE dbo.API_User ( id int NOT
I am trying to create a generic formatter/parser combination. Example scenario: I have a
Scenario: I have a document I created using LaTeX (my resume in this case),
I have the following scenario. I have created an ASP.NET web application (framework 3.5)
I have a path defined: when /the admin home\s?page/ /admin/ I have scenario that
I have a scenario where I have to check whether user has already opened
I have a scenario. (Windows Forms, C#, .NET) There is a main form which
I have the following scenario. A cube created in SSAS 2008. I can connected

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.