Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @model Models.MenuItemsViewModel
- @{
- ViewBag.Title = "Menus";
- Layout = "~/Views/Shared/_Layout.cshtml";
- }
- <div class="jumbotron">
- <h1 class="display-4">@ViewBag.Title</h1>
- <p>here you can set values</p>
- </div>
- @using (Html.BeginForm("Save", "MenuItems", FormMethod.Post))
- {
- <h2>Menus</h2>
- <table class="table">
- <thead>
- <tr>
- <th scope="col">Name</th>
- <th scope="col">Status</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- @Html.LabelFor(m => m.Schedule)
- </td>
- <td> @Html.CheckBoxFor(m => m.Schedule, new { @checked = Model.Schedule }) </td>
- </tr>
- <tr>
- <td>
- @Html.LabelFor(m => m.FAQ)
- </td>
- <td> @Html.CheckBoxFor(m => m.FAQ, new { @checked = Model.FAQ }) </td>
- </tr>
- </tbody>
- </table>
- <input type="submit" value="Save these values" class="btn btn-primary btn-block" />
- }
- using System.Linq;
- using System.Threading.Tasks;
- using System.Web.Mvc;
- using Models;
- namespace Controllers
- {
- [RoutePrefix("menuItems")]
- [Authorize(Roles = LoginController)]
- public class MenuItemsController : Controller
- {
- private readonly AppContext context = new AppContext();
- [Route("")]
- public async Task<ActionResult> Index()
- {
- var menuItems = context.MenuItems.SingleOrDefault();
- return View(new MenuItemsViewModel(menuItems));
- }
- [HttpPost] //I want to call this method when I press save!
- public ActionResult Save(MenuItemsViewModel model)
- {
- var menuItems = context.MenuItems.SingleOrDefault();
- if (menuItems == null)
- {
- ViewBag.Message = "Something went wrong";
- }
- model.UpdateFromViewModel(menuItems);
- ViewBag.Message = "Informationen sparades";
- context.SaveChanges();
- return RedirectToAction("Index");}
- }
- }
Add Comment
Please, Sign In to add comment