Не отображается код в браузере
Не отображается код в браузере
@using Shop.Data.Models;
@model IEnumerable<Car>
@{
ViewData["Title"] = "Главная страница";
}
@{
Layout = "_Layout";
}
<form method="post" asp-controller="Cars"></form>
<h1>Все автомобили</h1>
<br />
@foreach(var car in Model)
{
<div>
<h2>Модель:@car.Name</h2>
<p>Цена: @car.Price.ToString("c")</p>
</div>
}
<br />
Выдает код текстом в самом браузере Вот контроллер
using Microsoft.AspNetCore.Mvc;
using Shop.Data.Interfaces;
using Shop.ViewModels;
namespace Shop.Controllers
{
public class CarsController: Controller
{
private readonly IAllCars _allCars;
private readonly ICarsCategory _allCategories;
public CarsController(IAllCars iAllCars, ICarsCategory iCarsCat)
{
_allCars= iAllCars;
_allCategories= iCarsCat;
}
[Route("List")]
public ViewResult List()
{
ViewBag.Title = "Страница с автомобилями";
CarsListViewModel obj = new()
{
allCars = _allCars.Cars,
currCategory = "Автомобили"
};
return View(obj);
}
}
}
Возможно проблема в самом program.cs
using Shop.Data.Interfaces;
using Shop.Data.Mockc;
namespace Shop
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
var app = builder.Build();
app.Run(async (context) =>
{
context.Response.ContentType = "text/html";
await context.Response.SendFileAsync("Views/Cars/List.cshtml");
});
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for
production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
static void ConfigureServices(IServiceCollection services)
{
ConfigureServices(services);
services.AddTransient<IAllCars, MockCars>();
services.AddTransient<ICarsCategory, MockCategory>();
services.AddMvc();
services.AddMvc(option => option.EnableEndpointRouting = false);
}
app.UseDeveloperExceptionPage();
app.UseStatusCodePages();
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllerRoute(
name:"default",
pattern: "{controller=Cars}/{action=List}/{id?}");
app.UseAuthorization();
app.MapRazorPages();
app.Run();
}
}
}
Ошибок никаких нет при этом