zoukankan      html  css  js  c++  java
  • mvc 默认访问 Area 下控制器方法

    在MVC项目中经常会使用到Area来分开不同的模块让项目结构更加的清晰。如果想网站打开默打开Area下的控制器时会出现以下的错误

    “/”应用程序中的服务器错误。
    
    未找到视图“Index”或其母版视图,或没有视图引擎支持搜索的位置。搜索了以下位置: 
    ~/Views/Default/Index.aspx
    ~/Views/Default/Index.ascx
    ~/Views/Shared/Index.aspx
    ~/Views/Shared/Index.ascx
    ~/Views/Default/Index.cshtml
    ~/Views/Default/Index.vbhtml
    ~/Views/Shared/Index.cshtml
    ~/Views/Shared/Index.vbhtml

    解决方法:

    public static void RegisterRoutes(RouteCollection routes)
    {
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
      routes.MapRoute(
          name: "Default",
          url: "{controller}/{action}/{id}",
          defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional},
          namespaces:new string[]{"MVCUI.Areas.自己Area的名称.Controllers"}
          ).DataTokens.Add("Area","自己Area的名称");
    }

    超链接使用法:

    return RedirectToAction("action", "controller", new { area = "area-name" });
    <%= Html.ActionLink("超链接内容", "action", "controller", new { area = "area-name" }, null) %>
  • 相关阅读:
    Spring 基于构造函数的依赖注入
    SpringMVC后台接受前台传值的方法
    Spring--jar包
    Ubuntu扩展磁盘空间
    在VScode中运行C/C++
    一个好用的C语言操作
    Python下载超快
    Python多线程
    C语言回调函数
    VScode中运行python
  • 原文地址:https://www.cnblogs.com/superfeeling/p/9221265.html
Copyright © 2011-2022 走看看