[HttpGet] public ActionResult Edit(int? entryId) { var customerViewModel = new EditEntryViewModel(); if (entryId.HasValue) { Entry customer = _db.Entries.SingleOrDefault(x => x.Id == entryId); if (customer != null) { customerViewModel.Title = customer.Title; customerViewModel.Username = customer.Username; customerViewModel.Password = customer.Password; customerViewModel.Url = customer.Url; customerViewModel.Description = customer.Description; } } return View(customerViewModel); } [HttpPost] public ActionResult Edit(EditEntryViewModel viewModel) { if (ModelState.IsValid) { var entryToUpdate = _db.Entries.Single(p => p.Id == viewModel.Id); var entry = new Entry(); entry.Title = viewModel.Title; entry.Username = viewModel.Username; entry.Password = viewModel.Password; entry.Url = viewModel.Url; entry.Description = viewModel.Description; _db.Save(); return RedirectToAction("Detail", "Department", new { id = viewModel.Id }); } return View(viewModel); }
@using (Html.BeginForm()) { @Html.AntiForgeryToken() @Html.ValidationSummary(true) <fieldset> <legend>EditEntryViewModel</legend> @Html.HiddenFor(model => model.Id) <div class="editor-label"> @Html.LabelFor(model => model.Title) </div> <div class="editor-field"> @Html.EditorFor(model => model.Title) @Html.ValidationMessageFor(model => model.Title) </div> <div class="editor-label"> @Html.LabelFor(model => model.Username) </div> <div class="editor-field"> @Html.EditorFor(model => model.Username) @Html.ValidationMessageFor(model => model.Username) </div> <div class="editor-label"> @Html.LabelFor(model => model.Password) </div> <div class="editor-field"> @Html.EditorFor(model => model.Password) @Html.ValidationMessageFor(model => model.Password) </div> <div class="editor-label"> @Html.LabelFor(model => model.Url) </div> <div class="editor-field"> @Html.EditorFor(model => model.Url) @Html.ValidationMessageFor(model => model.Url) </div> <div class="editor-label"> @Html.LabelFor(model => model.Description) </div> <div class="editor-field"> @Html.EditorFor(model => model.Description) @Html.ValidationMessageFor(model => model.Description) </div> <p> <input type="submit" value="Save" /> </p> </fieldset> }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)