【问题标题】:HTTP 404 Server Error in '/' Application. in ASP.NET MVC 4“/”应用程序中的 HTTP 404 服务器错误。在 ASP.NET MVC 4
【发布时间】:2016-08-17 08:34:57
【问题描述】:

`首先,这是我的第一个 MVC 代码 & 我试图在这个站点中搜索问题的解决方案 & 我检查了所有可能的情况,如 routeconfig 文件、控制器、动作属性 & 我试图在指定的值中放置适当的值项目属性的 Web 选项卡页面。但它仍然显示相同的错误。请帮忙。

这里是我的路由配置文件

namespace Deepak_MVC_2
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Student", action = "GetStudents", id = UrlParameter.Optional }
            );
        }
    }
}

特定页面条目:Student/GetStudents

namespace Deepak_MVC_2.Controllers
{
    public class StudentController : Controller
    {
        public ActionResult GetAllStudent()
        {
            StudentModelManager smm = new StudentModelManager();
            List<StudentModel> lsm = smm.GetAllStudentInfo();
            ActionResult ar = View("GetStudents",lsm);
            return ar;
        }
    }
}

【问题讨论】:

  • 能否请您宣传一下您的控制器代码?
  • StudentController中有GetStudents的动作方法吗?
  • 不,操作方法是GetAllStudent()。你现在可以看到,因为我已经更新了它。视图名称是 GetStudents.cshtml。

标签: c# asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing


【解决方案1】:

更新控制器的操作以匹配所需的视图。这样您实际上可以在返回视图时删除名称,因为约定会将ViewName 与操作名称匹配。

namespace Deepak_MVC_2.Controllers
{
    public class StudentController : Controller
    {
        public ActionResult GetStudents()
        {
            StudentModelManager smm = new StudentModelManager();
            List<StudentModel> lsm = smm.GetAllStudentInfo();
            ActionResult ar = View(lsm);
            return ar;
        }
    }
}

这将允许

GET /Student/GetStudents

与图像中的正确视图相匹配

【讨论】:

    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 2013-12-02
    • 1970-01-01
    相关资源
    最近更新 更多