1

It's my first question! In my project when I'm input date in special page, it is saved to database, but when I edit this information in other page it is not display, and i should input information about date again....

It is view for create and edit information:

 <div class="editor-label"> @Html.LabelFor(model => model.DatePol) </div> <div class="editor-field"> @Html.EditorFor(model => model.DatePol) @Html.ValidationMessageFor(model => model.DatePol) </div> Controller (part of edit): // // GET: /Uchet/Edit/5 public ActionResult Edit(string userName, string nameTitle, int id = 0) { var NameLst = new List<string>(); var NameQry = from b in db.Users orderby b.Name select b.Name; NameLst.AddRange(NameQry.Distinct()); ViewBag.userName = new SelectList(NameLst); var TitleLst = new List<string>(); var TitleQry = from r in db.Lib orderby r.Title select r.Title; TitleLst.AddRange(TitleQry.Distinct()); ViewBag.nameTitle = new SelectList(TitleLst); Uchet uchet = db.Uchets.Find(id); if (uchet == null) { return HttpNotFound(); } return View(uchet); } // // POST: /Uchet/Edit/5 [HttpPost] public ActionResult Edit(Uchet uchet) { if (ModelState.IsValid) { db.Entry(uchet).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(uchet); } 
16
  • what is the problem in this code? Commented Mar 20, 2014 at 7:26
  • @RahulRJ When I edit information date value not show... I can't see inputed info... Commented Mar 20, 2014 at 7:30
  • are You same view for create and edit then are u passing object in your controller Commented Mar 20, 2014 at 7:31
  • @Dinesh Yes, same, but information of other types (int, string) saves :D Commented Mar 20, 2014 at 7:37
  • Show your controller code Commented Mar 20, 2014 at 7:39

1 Answer 1

1

Try like This

 Uchet uchet = db.Uchets.Find(id); if (uchet == null) { return HttpNotFound(); } else { uchet.Datepol = db.tablename.FirstOrDefault(s => s.columnname == id).datetimeFieldName; //Like this you can retrive your date time in that brackets are your conditions } return View(uchet); 
Sign up to request clarification or add additional context in comments.

11 Comments

What i cannot understand inputed page means
Sorry! Date value was inputed in other page of project. And I don't undrestand how can I assign uchet.Datepol to this inputed value...
ok you getting the date value from Create page then stored in database and than you can show that date in edit page may i right. now what u try to do
Then what is a problem now
are you want to show a the date in edit page but no one can edit the date field that why u need (Sorry for telling this are you tamil then just comment in tamil because i m not understand your english Sorry once again )
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.