Имя View не существует в текущем контексте
Это потому, что ваш контроллер наследуется от ControllerBase
. Вы можете проверить исходный код ниже, ControllerBase
не содержит View()
метод по умолчанию. Controller
наследуется от ControllerBase
и добавляет поддержку представления:
//A base class for an MVC controller with view support.
public abstract class Controller : ControllerBase, IActionFilter, IFilterMetadata, IAsyncActionFilter, IDisposable
{
protected Controller();
// Summary:
// Creates a Microsoft.AspNetCore.Mvc.ViewResult object that renders a view to the
// response.
//
// Returns:
// The created Microsoft.AspNetCore.Mvc.ViewResult object for the response.
[NonAction]
public virtual ViewResult View();
//
// Summary:
// Creates a Microsoft.AspNetCore.Mvc.ViewResult object by specifying a viewName.
//
// Parameters:
// viewName:
// The name or path of the view that is rendered to the response.
//
// Returns:
// The created Microsoft.AspNetCore.Mvc.ViewResult object for the response.
[NonAction]
public virtual ViewResult View(string viewName);
//
// Summary:
// Creates a Microsoft.AspNetCore.Mvc.ViewResult object by specifying a viewName
// and the model to be rendered by the view.
//
// Parameters:
// viewName:
// The name or path of the view that is rendered to the response.
//
// model:
// The model that is rendered by the view.
//
// Returns:
// The created Microsoft.AspNetCore.Mvc.ViewResult object for the response.
[NonAction]
public virtual ViewResult View(string viewName, object model);
//
// Summary:
// Creates a Microsoft.AspNetCore.Mvc.ViewResult object by specifying a model to
// be rendered by the view.
//
// Parameters:
// model:
// The model that is rendered by the view.
//
// Returns:
// The created Microsoft.AspNetCore.Mvc.ViewResult object for the response.
[NonAction]
public virtual ViewResult View(object model);
}
В таком сценарии просто измените ControllerBase
на Controller
:
public class ProductController : Controller { }
Кроме того, я вижу, что ваша структура содержит Razor Pages. Когда вы используете return View(model)
, она будет отображать бритвенное представление с данными модели. Убедитесь, что у вас есть бритвенное представление с именем ProductInfo.cshtml
вместо бритвенных страниц с именем ProductInfo.cshtml
.