Прописал путь котроллер + имя метода(названия представления) но возвращает ошибку 404. Что делать?
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddTransient<IAllCars, MockCars>();
services.AddTransient<ICarsCategory, MockCategory>();
}
@using WebApplication29.Data.Models
@model IEnumerable<Car>
@{
Layout = null;
}
<!DOCKTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width"/>
<title>List</title>
</head>
<body>
<h2>Все автомобили</h2>
@{
foreach(var car in Model)
{
<div>
<h2>Модель: @car.name</h2>
<p>Цена: @car.price.ToString("c")</p>
</div>
}
}
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebApplication29.Data.Models
{
public class Car
{
public int id { set; get; }
public string name { set; get; }
public string shortDesc { set; get; }
public string longDesc { set; get; }
public string img { set; get; }
public ushort price { set; get; }
public bool isFavourite { set; get; }
public bool available { set; get; }
public int categoryId { set; get; }
public virtual Category Category { set; get; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication29.Data.interfaces;
using WebApplication29.Data.Models;
namespace WebApplication29.Data.mocks
{
public class MockCars : IAllCars
{
private readonly ICarsCategory _categoryCars = new MockCategory();
public IEnumerable<Car> Cars
{
get
{
return new List<Car>
{
new Car {
name="Tesla",
shortDesc="Автомобиль класса люкс",
longDesc="Стильный дизайн",
img="img/Tesla.jpg",
price=45000,
isFavourite=true,
available=true,
Category = _categoryCars.AllCategories.First()
},
new Car {
name="Porsche",
shortDesc="Дерзкий автомобиль",
longDesc="Красивый и скоростной",
img="img/Porsche.jpg",
price=45000,
isFavourite=true,
available=true,
Category = _categoryCars.AllCategories.Last()
},
new Car {
name="Nissan",
shortDesc="Удобный",
longDesc="Автомобиль для городской жизни",
img="img/Nissan.jpg",
price=45000,
isFavourite=true,
available=true,
Category = _categoryCars.AllCategories.Last()
},
new Car {
name="Cadillac",
shortDesc="Стильный",
longDesc="Автомобиль идеално впишется в интерьер",
img="img/Cadilac/jpg",
price=45000,
isFavourite=true,
available=true,
Category = _categoryCars.AllCategories.First()
},
};
}
}
public IEnumerable<Car> getFavCars { get; set; }
IEnumerable<Car> IAllCars.Cars { get => throw new NotImplementedException(); }
public Car getObjectCar(int carId)
{
throw new NotImplementedException();
}
}
}
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication29.Data.interfaces;
namespace WebApplication29.Controllers
{
public class CarsController : Controller
{
private readonly IAllCars _allCars;
private readonly ICarsCategory _allCategories;
public CarsController(IAllCars iAllCars, ICarsCategory _iCarsCat)
{
_allCars = iAllCars;
_allCategories = _iCarsCat;
}
public ViewResult Index()
{
var cars = _allCars.Cars;
return View();
}
}
}