【问题标题】:Asp.Net Core 2.0 Search My View In SharedAsp.Net Core 2.0 在共享中搜索我的视图
【发布时间】:2017-11-20 09:48:30
【问题描述】:

我有两个参数(页面,标题)的控制器重定向到查看时出现问题返回以下错误

InvalidOperationException:未找到视图“索引”。这 搜索了以下位置:/Views/Shared/Index.cshtml

如果我让我的控制器接受一个参数,控制器工作正常。

  [Route("~/Section/{page}/{title}")]
    public async Task<IActionResult> Index(int page,string title)
    {
        SectionViewModel model = new SectionViewModel();
        var category =await _categoryService.GetCategory(CommonHelper.DashToSpace(title));
        model.news =await _newsService.GetNewsByCategory(category.Id.ToString(),pageIndex: 1);
        return View(model);
    }

【问题讨论】:

  • [Route("~/Section/{page}/{title}")] 更改为 [Route("Section/{page}/{title}")]
  • 还是不行
  • 您是否有一个名为 Index 的视图与该特定控制器位于同一文件夹中?
  • 是的,我让控制器接受一个参数工作正常,但是当我添加两个参数时,当我将名为 index 的视图从部分文件夹移动到使用两个参数的共享文件夹时也不起作用
  • 这与路由、参数或任何其他废话无关。当您返回 View(model) 时,它将寻找 Views\{ControllerName}\Index.cshtmlViews\Shared\Index.cshtml。该错误告诉您它也找不到。找出原因,你就是金子。

标签: c# asp.net-core


【解决方案1】:

错误消息说它在 Shared 文件夹中查找名为 Index 的视图。

您在 /Views/{Controller}/Index.cshtml 中有视图吗?

【讨论】:

  • 是的,在 /Views/{Controller}/Index.cshtml 中有一个视图
  • 我猜它适用于正确文件夹中的视图。
猜你喜欢
  • 2018-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-02
  • 2018-02-17
  • 2019-11-28
  • 2018-09-09
相关资源
最近更新 更多