【发布时间】:2020-07-10 16:15:22
【问题描述】:
一个简单的问题。尝试从控制器方法返回视图时出现以下错误。
名称 View 在当前上下文中不存在
参考这张图片来了解我的项目结构 -- https://pasteboard.co/Jh1AxGy.png
我的代码是
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using AutoMapper;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Authorization;
using CoreSpeechService.App.Utility;
public IActionResult ProductInfo(int p_id)
{
if(p_id>0)
{
var pEntity = pService.GetProductById(p_id);
if(pEntity!=null)
{
ViewData["ProductId"] = pEntity.Id;
return View(pEntity);
}
else
{
return RedirectToAction("Index");
}
}
else
{
return BadRequest("Could not fetch detailes related to this product at the moment. Please try later.");
}
}
有人会认为我已经在控制器中添加了所有必要的命名空间。显然不是。我有一种预感,这主要是由于我的项目结构 [控制器和 cshtml 文件]。正确的脚手架问题?什么 应该做吗?
建议。谢谢
** 值得一提 - 我的控制器继承自 ControllerBase 而不是 Controller。
【问题讨论】:
标签: asp.net-core view controller asp.net-core-2.2 viewdata