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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:38:30+00:00 2026-05-26T06:38:30+00:00

I created my first MVC application in ASP.NET today. I have a datetime column

  • 0

I created my first MVC application in ASP.NET today. I have a datetime column “CreatedAt” which should be filled by current date without being visible in the input form. But the generated code has this code:

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

It displays a textbox in input form. I don’t want to display it, instead it should be set in code behind. How can I do that?

  • 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-26T06:38:31+00:00Added an answer on May 26, 2026 at 6:38 am

    ASP.NET MVC doesn’t have a concept of a ‘code-behind’. Quite simply, you send data from your View, and it’s processed in your Controller.

    So if this is an action that POSTs, then we can send data back to the controller, and even better, we can keep that data ‘hidden’ from the textbox view.

    In your view, you should replace that with the following line:

     @Html.HiddenFor(m => m.CreatedAt, DateTime.Now);
    

    Then when the model is POSTed to the controller, the CreatedAt property will have the DateTime.Now filled in.

    When you POST something, it has to go to an Action Method:

    public class MyController : Controller
    {
    //other stuff

    [HttpPost]
    public ActionResult Edit(Product product)
    {
        product.CreatedAt // should equal the DateTime.Now set when you created the View
    }
    

    }

    or you could set it in the controller after it POSTs:

    public class MyController : Controller
    {
    //other stuff

    [HttpPost]
    public ActionResult Edit(Product product)
    {
        product.CreatedAt = DateTime.Now;
    }
    

    }

    You may run into issues with Html.Hidden in this context, if you do, make sure to use the work around in place.

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

Sidebar

Related Questions

I created an ASP.NET MVC 2.0 Application. It ran fine at first test and
I have a wizard in my asp.net MVC application which is built upon this
I am working on asp.net MVC 3 application and I have created a model.
I have an ASP.NET MVC application where I am editing an existing database to
I'm building my first ASP.NET MVC application and I am having some troubles with
I have an ASP.NET MVC 3 project that I just created using the project
I have my asp.net mvc 3 application with entity framework and i used the
Have just started converting an existing job tracking system into an ASP.NET MVC application.
I created a web application using ASP.Net MVC 3 and EF 4.1, and I
Here's my situation: I have been working on an ASP.NET MVC 3 application for

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.