zoukankan      html  css  js  c++  java
  • asp.net mvc5 配置自定义路径

    首先配置路由文件,默认页是第一个路由的配置:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    
    namespace WebApplication1
    {
        public class RouteConfig
        {
            public static void RegisterRoutes(RouteCollection routes)
            {
                routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
                routes.MapRoute(
                    name: "path1",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Path1", action = "Index", id = UrlParameter.Optional }
                );
    
                routes.MapRoute(
                    name: "path2",
                    url: "{controller}/{action}/{id}",
                    defaults: new { controller = "Path2", action = "Index", id = UrlParameter.Optional }
                );
            }
        }
    }
    View Code

    然后右键项目,添加-搭建基架项。添加控制器和视图。

    添加的视图必须位于view目录下,因为它就是路径。可以参考:

    访问路径就是:

    http://localhost/Path1/Index

    http://localhost/Path2/Index

    另外,控制器返回视图最好不要返回空,否则会出现奇怪的错误。

  • 相关阅读:
    javascript 构造函数,工厂模式,稳妥构造函数浅析
    javascript基本概念
    struts2 类型转换
    struts action
    struts2 配置(部分)
    struts2基本构成
    charapter 1
    java 内部类
    mysql zip 解压安装 (win10)
    python之random模块
  • 原文地址:https://www.cnblogs.com/hont/p/4250877.html
Copyright © 2011-2022 走看看