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?
if the date is needed in a post you can do
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
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.
then in your view something like
Hopefully this should give you some idea of how to fix your code