Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IActionResult Edit(int id) {
- var model = this.categoryService.GetById(id);
- return View(model);
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public IActionResult Edit(CategoriesViewModel model) {
- if (ModelState.IsValid) {
- this.categoryService.Update(model);
- return RedirectToAction(nameof(Category));
- }
- return this.View(model.Id);
- }
- //View
- @using CakeStore.App.Areas.Admin.Models.Categories;
- @model CategoriesViewModel
- @{
- ViewData["Title"] = "Edit";
- Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
- }
- <h1 class="text-center text-header-page">Edit Category</h1>
- <hr class="hr-admin-divider" />
- <form class="mx-auto w-50 form-horizontal" method="post" action="Edit">
- <div asp-validation-summary="ModelOnly" class="text-danger"></div>
- <div class="form-group">
- <input asp-for="@Model.Id" type="hidden" name="id" value="@Model.Id"/>
- </div>
- <div class="form-group">
- <label asp-for="@Model.Name"></label>
- <input asp-for="@Model.Name" type="text" value="@Model.Name" class="form-control" id="name" name="name">
- <span asp-validation-for="@Model.Name" class="text-danger"></span>
- </div>
- <div class="button-holder d-flex justify-content-center">
- <button type="submit" class="btn button-black-white">Edit</button>
- </div>
- </form>
- //Model
- namespace CakeStore.App.Areas.Admin.Models.Categories {
- public class CategoriesViewModel {
- public int Id { get; set; }
- [Required]
- [StringLength(22,MinimumLength =3,ErrorMessage =AdminConstants.NameRange)]
- public string Name { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement