locked
Model within Areas not displaying RRS feed

  • Question

  • User2074931137 posted

    Error

    https://localhost:44332/dining/ingredient/

    This localhost page can’t be found

    No webpage was found for the web address:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    
    namespace Domus.Areas.Dining.Models
    {
        public class Ingredient
        {
            public int IngredientID {get; set;}
    
            public string IngredientDesignator { get; set; }
        }
    }

    SQL Server Object Explorer
         SQL Server
              (local db)/MSQL LocalDB...
                   Databases
                        Domus
                             Tables
                                  dbo.Ingredient
                                       Columns
                                            IngredientID (PK, int, not null)
                                            IngredientDesignator (nvchar) max, null)

    @model IEnumerable<Domus.Areas.Dining.Models.Ingredient>
    
    @{
        ViewData["Title"] = "Index";
    }
    
    <h1>Index</h1>
    
    <p>
        <a asp-action="Create">Create New</a>
    </p>
    <table class="table">
        <thead>
            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.IngredientDesignator)
                </th>
                <th></th>
            </tr>
        </thead>
        <tbody>
    @foreach (var item in Model) {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.IngredientDesignator)
                </td>
                <td>
                    <a asp-action="Edit" asp-route-id="@item.IngredientID">Edit</a> |
                    <a asp-action="Details" asp-route-id="@item.IngredientID">Details</a> |
                    <a asp-action="Delete" asp-route-id="@item.IngredientID">Delete</a>
                </td>
            </tr>
    }
        </tbody>
    </table>

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.AspNetCore.Mvc.Rendering;
    using Microsoft.EntityFrameworkCore;
    using Domus.Areas.Dining.Models;
    using Domus.Data;
    
    namespace Domus.Areas.Dining.Controllers
    {
        [Area("Dining")]
        public class IngredientController : Controller
        {
            private readonly HomeContext _context;
    
            public IngredientController(HomeContext context)
            {
                _context = context;
            }
    
            // GET: Dining/Ingredient
            public async Task<IActionResult> Index()
            {
                return View(await _context.Ingredient.ToListAsync());
            }
    
            // GET: Dining/Ingredient/Details/5
            public async Task<IActionResult> Details(int? id)
            {
                if (id == null)
                {
                    return NotFound();
                }
    
                var ingredient = await _context.Ingredient
                    .FirstOrDefaultAsync(m => m.IngredientID == id);
                if (ingredient == null)
                {
                    return NotFound();
                }
    
                return View(ingredient);
            }
    
            // GET: Dining/Ingredient/Create
            public IActionResult Create()
            {
                return View();
            }
    
            // POST: Dining/Ingredient/Create
            // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
            // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
            [HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<IActionResult> Create([Bind("IngredientID,IngredientDesignator")] Ingredient ingredient)
            {
                if (ModelState.IsValid)
                {
                    _context.Add(ingredient);
                    await _context.SaveChangesAsync();
                    return RedirectToAction(nameof(Index));
                }
                return View(ingredient);
            }
    
            // GET: Dining/Ingredient/Edit/5
            public async Task<IActionResult> Edit(int? id)
            {
                if (id == null)
                {
                    return NotFound();
                }
    
                var ingredient = await _context.Ingredient.FindAsync(id);
                if (ingredient == null)
                {
                    return NotFound();
                }
                return View(ingredient);
            }
    
            // POST: Dining/Ingredient/Edit/5
            // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
            // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
            [HttpPost]
            [ValidateAntiForgeryToken]
            public async Task<IActionResult> Edit(int id, [Bind("IngredientID,IngredientDesignator")] Ingredient ingredient)
            {
                if (id != ingredient.IngredientID)
                {
                    return NotFound();
                }
    
                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(ingredient);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!IngredientExists(ingredient.IngredientID))
                        {
                            return NotFound();
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return RedirectToAction(nameof(Index));
                }
                return View(ingredient);
            }
    
            // GET: Dining/Ingredient/Delete/5
            public async Task<IActionResult> Delete(int? id)
            {
                if (id == null)
                {
                    return NotFound();
                }
    
                var ingredient = await _context.Ingredient
                    .FirstOrDefaultAsync(m => m.IngredientID == id);
                if (ingredient == null)
                {
                    return NotFound();
                }
    
                return View(ingredient);
            }
    

    Tuesday, April 14, 2020 3:30 PM

Answers