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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:08:22+00:00 2026-06-02T09:08:22+00:00

I want to insert a fixed date into table. How can I do this

  • 0

I want to insert a fixed date into table. How can I do this ?

    <div class="editor-label">
        Description :
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.Description, new { @class = "textboxes" })
        @Html.ValidationMessageFor(model => model.Description)
    </div>

    <div class="editor-label">
        Date :
    </div>
    <div class="editor-field">
        @Html.TextBoxFor(model => model.Date, new { @class = "textboxes" }) /// I wanna be here a fixed date .
        @Html.ValidationMessageFor(model => model.Date)
    </div>

My controller code is:

public ActionResult Index(tblOrder tblorder)
        {
            if (ModelState.IsValid)
            {
                db.tblOrders.AddObject(tblorder);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.fxBudjet = new SelectList(db.tblBudjets, "ID", "Budjet", tblorder.fxBudjet);
            ViewBag.fxServiceType = new SelectList(db.tblServiceTypes, "ID", "Service", tblorder.fxServiceType);
            ViewBag.fxStartTime = new SelectList(db.tblStartDates, "ID", "StartDate", tblorder.fxStartTime);
            return View(tblorder);
        }

Do I need to change my controller code?

  • 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-02T09:08:23+00:00Added an answer on June 2, 2026 at 9:08 am
    @Html.DisplayTextFor(model => model.Date, new { @class = "textboxes" })
    

    if the date is needed in a post you can do

    @Html.DisplayTextFor(model => model.Date, new { @class = "textboxes" })
    @Html.HiddenFor(model => model.Date)
    

    or in the post method you can use TryUpdateModel and exclude the date field

    Edit from your update i would set the value for the model in the controller e.g. say you had a class year that you wanted to prepopulate the year value

        public ActionResult Create()
        {
            return View(new Year() { Value = DateTime.Now.Year });
        }
    

    again if you want it for the post you can use a hiddenfor or else regenerate it in the post

    if this field is only required in the post method a better option might be to create a viewmodel without that field and then have some mapping logic in the post method

    Edit 2: As with MVC music store you should really have 2 methods a get and a post. I will assume it is for a create.

    [HttpGet]
    public ActionResult Create()
    {
        ViewBag.fxBudjet = new SelectList(db.tblBudjets, "ID", "Budjet");
        ViewBag.fxServiceType = new SelectList(db.tblServiceTypes, "ID", "Service");
        ViewBag.fxStartTime = new SelectList(db.tblStartDates, "ID", "StartDate");
        return View(new tblOrder() { Date = DateTime.Now });
    }
    
    [HttpPost]
    public ActionResult Create(tblOrder tblorder)
    {
        if (ModelState.IsValid)
        {
            db.tblOrders.AddObject(tblorder);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    
        ViewBag.fxBudjet = new SelectList(db.tblBudjets, "ID", "Budjet", tblorder.fxBudjet);
        ViewBag.fxServiceType = new SelectList(db.tblServiceTypes, "ID", "Service", tblorder.fxServiceType);
        ViewBag.fxStartTime = new SelectList(db.tblStartDates, "ID", "StartDate", tblorder.fxStartTime);
        return View(tblorder);
    }
    

    then in your view something like

    @model tblOrder
    
    @Html.BeginForm()
    {
        @Html.DisplayTextFor(model => model.Date, new { @class = "textboxes" })
        @Html.HiddenFor(model => model.Date)
        ...other form stuff
        <input type="submit" value="Delete" />
    }
    

    Hopefully this should give you some idea of how to fix your code

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

Sidebar

Related Questions

I want to create trigger which will be fired after insert into some table,
I want to insert a range of values into my table create TEMPORARY TABLE
I want to insert list view subitems in wpf. I am using this code
I want to insert say 50,000 records into sql server database 2000 at a
I want to insert something into a STL list in C++, but I only
I want to insert a new row into an Access database. I'm looking at
I want to insert multiple invisible watermarks into my JPEG pictures through C# code.
I'm doing a bulk insert from a fixed width text file using INSERT INTO
I'm trying to post data with AJAX and insert it into a database table.
I have a fixed sized array in Matlab. When I want to insert a

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.