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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:46:05+00:00 2026-06-14T04:46:05+00:00

I am building my first MVC site using MVC 4 in C# and Entity

  • 0

I am building my first MVC site using MVC 4 in C# and Entity Framework 4.1. I have a model that displays a list of items with standard “add”, “edit”, “details”, and “delete” options.

The database that’s linked to the model has a column for “Username” and my application currently displays a text box for the user to enter their username via the following code from the Create.cshtml file.

    <div class="editor-field">
        @Html.EditorFor(model => model.UserName)
        @Html.ValidationMessageFor(model => model.UserName)
    </div>

I’m trying to alter this so that their User.Identity.Name (e.g. DOMAIN\user) value will either auto-populate in the text box, or even better, just be stored without showing the user that it’s happening.

Is there a relatively painless way to accomplish this?

EDIT: My Controller code for the “create” section currently looks like this:

    public ActionResult Create(Occurrence occurrence)
    {
        if (ModelState.IsValid)
        {
            db.Occurrences.Add(occurrence);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        ViewBag.EmployeeID = new SelectList(db.Employees, "EmployeeID", "EmployeeName", occurrence.EmployeeID);
        return View(occurrence);
    }
  • 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-14T04:46:06+00:00Added an answer on June 14, 2026 at 4:46 am

    You can set the username in the controller

    public ActionResult Create()
    {
        string username = Environment.UserName // or however you get it
        User user = new User{UserName = username};
        return View(user);
    }
    

    another option is to handle it in the view

    @Html.ValidationMessageFor(model => model.UserName, new{@Value = Environment.UserName})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an ASP.NET MVC 3 site using the code-first Entity Framework 4 approach.
I'm very new to MVC, and just building my first site, using NerdDinner as
I'm building a MVC 3 application and use Entity Framework 4.3 code-first. My context
I am building an ASP.NET MVC web application using entity framework DbContext using the
I'm building a web app using EF Code First and ASP.NET MVC. I have
I'm building a simple code-first MVC 3 blog like application. My model has three
I'm building my first jquery mobile site and have run into a problem. When
I'm building a very simple ASP.NET MVC site that doesn't require a database and
I'm building an ASP.NET MVC site where I want to have a Google Maps
I am building my first ASP.Net MVC based app and have a problem accessing

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.