Код: Выделить всё
Layout = _DashboardLayout
Вот ошибка:
NullReferenceException: ссылка на объект не установлена на экземпляр объекта.
AspNetCoreGeneratedDocument.Views_Dashboard_Inventory_Create.ExecuteAsync() в Create.cshtml
...
Это как-то связано с этим, но немного отличается, потому что Проблема заключалась в _DashboardLayout.
Исключение ASP.NET Core NullReferenceException при простом доступе к модели
Вот код моего InventoryController код>:
Код: Выделить всё
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Gravitywears.Entities;
using Gravitywears.Models;
using System.Threading.Tasks;
namespace Gravitywears.Controllers.Dashboard
{
// [Route("Dashboard/[controller]")]
public class InventoryController : Controller
{
private readonly AppDbContext _context;
public InventoryController(AppDbContext context)
{
_context = context;
}
// ...
[HttpPost("Dashboard/Inventory/Create")]
[ValidateAntiForgeryToken]
public async Task Create([Bind("Id,ProductName,ProductBrand,Quantity,TypeOfProduct,Price,AgeRange")] Product product)
{
if (ModelState.IsValid)
{
try
{
_context.Add(product);
await _context.SaveChangesAsync();
ModelState.Clear();
TempData["SuccessMessage"] = "Product successfully created!";
return RedirectToAction("Create");
}
catch (DbUpdateException)
{
ModelState.AddModelError("", "Please enter a unique inputs.");
return View("~/Views/Dashboard/Inventory/Create.cshtml", product);
}
}
// If we got this far, something failed; redisplay form
TempData["ErrorMessage"] = "Failed to create product. Please check the form and try again.";
return View("~/Views/Dashboard/Inventory/Create.cshtml", product);
}
}
}
Код: Выделить всё
@{
Layout = "_DashboardLayout"; // Use the layout for consistent design
}
@model Gravitywears.Models.Product
@* *@
@* *@
@* *@
Type of Product
Cloth
Pants
Accessories
Sports Gear
Age
-18
18+
Create Item
Но поскольку ошибка была в макете, я не знаю, что мне с этим делать сейчас.
Подробнее здесь: https://stackoverflow.com/questions/790 ... out-in-asp
Мобильная версия