zoukankan      html  css  js  c++  java
  • MVC 自定义路由规则

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


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


                routes.MapRoute(
                    name:"NewsShow",
                    url:"{year}-{month}-{day}-{id}",
                    defaults:new {controller="News",action="Show"},
                    constraints:new
                    {
                        year="^\d{4}$",
                        month = "^\d{1,2}$",
                        day = "^\d{1,2}$",
                    }
                    );



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

    }


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


    namespace FirstMVC.Controllers
    {
        public class NewsController : Controller
        {
            //
            // GET: /News/


            public ActionResult Index()
            {
                return View();
            }

            //2014-1-1-5
            public ActionResult Show(int id, int year, int month, int day)
            {
                ViewBag.id = id;
                ViewBag.year = year;
                ViewBag.month = month;
                ViewBag.day = day;

                return View();
            }


        }
    }

  • 相关阅读:
    Python 集合
    Python sorted()
    CodeForces 508C Anya and Ghosts
    CodeForces 496B Secret Combination
    CodeForces 483B Friends and Presents
    CodeForces 490C Hacking Cypher
    CodeForces 483C Diverse Permutation
    CodeForces 478C Table Decorations
    CodeForces 454C Little Pony and Expected Maximum
    CodeForces 313C Ilya and Matrix
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434750.html
Copyright © 2011-2022 走看看