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();
            }


        }
    }

  • 相关阅读:
    网络流与线性规划24题 之 餐巾计划问题
    待刷题目分类(一)
    bzoj1787 [Ahoi2008]Meet 紧急集合
    Hoj2634 How to earn more?
    poj3281 Dining
    浅谈数论(三)水仙花数
    poj1637 Sightseeing tour
    动态规划的思考(1)
    网络流-最大流问题 ISAP 算法解释(转自Renfei Song's Blog)
    poj1273 Drainage Ditches
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434750.html
Copyright © 2011-2022 走看看