zoukankan      html  css  js  c++  java
  • MVC中路由的修改和浏览器的地址参数

    在 ASP.NET MVC 应用程序中,它是更常见的做法在作为路由数据 (像我们一样与身份证上面) 比将它们作为查询字符串传递的参数中传递。

    public string Welcome(string name, int ID = 1)
    {
        return HttpUtility.HtmlEncode("Hello " + name + ", ID: " + ID);
    }

    您也可以添加一条路线来传递name numtimes 作为路由数据的 URL 中的参数。App_StartRouteConfig.cs文件中,添加"Hello"路由:

    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 = "Home", action = "Index", id = UrlParameter.Optional }
          );
    
          routes.MapRoute(
               name: "Hello",
               url: "{controller}/{action}/{name}/{id}"
           );
       }
    }

    运行该应用程序,浏览至 /localhost:XXX/HelloWorld/Welcome/Scott/3.

    对于许多的 MVC 应用程序,默认路由工作正常。您将学习以后在本教程中,通过使用模型联编程序,数据和你不必修改默认路由的。

  • 相关阅读:
    自定义组件要加@click方法
    绑定样式
    647. Palindromic Substrings
    215. Kth Largest Element in an Array
    448. Find All Numbers Disappeared in an Array
    287. Find the Duplicate Number
    283. Move Zeroes
    234. Palindrome Linked List
    202. Happy Number
    217. Contains Duplicate
  • 原文地址:https://www.cnblogs.com/KKSoft/p/4495646.html
Copyright © 2011-2022 走看看