【问题标题】:The Resource cannot be found error in ASP.Net在 ASP.Net 中找不到资源错误
【发布时间】:2019-12-15 18:23:52
【问题描述】:

“/”应用程序中的服务器错误。 无法找到该资源。 说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下 URL 并确保其拼写正确。

请求的网址:/Movies/Random

版本信息:Microsoft .NET Framework 版本:4.0.30319; ASP.NET 版本:4.8.3928.0

这是我开始在线教程时显示的错误消息。这可能是什么原因???

Random.cshtml

@model Vidly.Models.Movie
 @{
ViewBag.Title = "Random";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>@Model.Name</h2>

电影.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Vidly.Models
{
    public class Movie
    {
    public int Id { get; set; }
    public string Name { get; set; }
    }
}

MoviesController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vidly.Models;

namespace Vidly.Controllers
{
    public class MoviesController : Controller
    {
        // GET: Movies/Random
        public ActionResult Index()
        {
            var movie = new Movie() { Name = "Hello" };

            return View(movie);
        }
    }
}

【问题讨论】:

  • 您没有指向应用程序的正确路径。引擎试图在您的Movies 控制器中找到一个名为Random 的操作方法,但显然它不存在。请查看您是如何在RouteConfig.cs 中设置路线的。

标签: c# asp.net .net visual-studio iis


【解决方案1】:

在 MoviesController.cs 中应该是

public ActionResult Random()

而不是

public ActionResult Index()

【讨论】:

  • 我更改了网址,但出现了同样的错误。当我们使用 /Movies/Index 时,视图名称是 Random.cshtml。要摆脱错误,应该将其更改为 index.cshtml,或者操作结果应该是随机的。我选择了后者。通过简单地更改 URL 不会产生正确的输出。无论如何,感谢您的建议并感谢您的帮助。我从这个愚蠢的错误中学到了很多。
猜你喜欢
  • 2012-03-06
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 2014-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-27
相关资源
最近更新 更多