第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

asp.net mvc中的路徑選擇

標(biāo)簽:
C

MVC的路径选择十分灵活,可以用类似/parm1/parm2/parm3/ 的方式(这个有点象iis的urlrewriter),也可以象传统url那样用/?parm1=a&parm2=b&parm3=c这样访问

关键是Global.asax中Route规则的配置

以下是一个Global.asax的示例:

 1protected void Application_Start(object sender, EventArgs e)
 2        {
 3            // Note: Change Url= to Url="[controller].mvc/[action]/[id]" to enable 
 4            //       automatic support on IIS6
 5
 6            RouteTable.Routes.Add(new Route
 7            {
 8                Url = "[controller]/[action]",
 9                Defaults = new { action = "Index" },
10                RouteHandler = typeof(MvcRouteHandler)
11            });
12
13
14            RouteTable.Routes.Add(new Route
15            {
16                Url = "[controller]/[action]/[id]",
17                Defaults = new { action = "Index", id = (int?)null },
18                RouteHandler = typeof(MvcRouteHandler)
19            });
20
21
22            RouteTable.Routes.Add(new Route
23            {
24                Url = "[controller]/[action]/[id]/[name]",
25                Defaults = new { action = "Index", name = (string)null,id=(int?)null },
26                RouteHandler = typeof(MvcRouteHandler)
27            });
28
29            RouteTable.Routes.Add(new Route
30            {
31                Url = "[controller]/[action]/[id]/[name]/[sex]",
32                Defaults = new { action = "Index", name = (string)null, id = (int?)null,sex=(string)null },
33                RouteHandler = typeof(MvcRouteHandler)
34            });   
35
36
37            RouteTable.Routes.Add(new Route
38            {
39                Url = "Default.aspx",
40                Defaults = new { controller = "Home", action = "Index", id = 2, name = "Jimmy",sex="female" },
41                RouteHandler = typeof(MvcRouteHandler)
42            });
43        }


对应的HomeController文件:

public class HomeController : Controller
    {       
        /// <summary>
        /// Example URL: /Home/Index/?id=2&name=abc&sex=male (对应Url = "[controller]/[action]")                     
        ///              /Home/Index/2/?name=abc&sex=male  (对应Url = "[controller]/[action]/[id]")          
        ///              /Home/Index/2/abc/?sex=male  (对应Url = "[controller]/[action]/[id]/[name]")
        ///              /Home/Index/2/abc/male/ (对应Url = "[controller]/[action]/[id]/[name]/[sex]")
        ///              /Home/Index/2/abc/  (对应Url = "[controller]/[action]/[id]/[name]")
        ///              /Home/Index/2/ (对应Url = "[controller]/[action]/[id]")
        /// </summary>
        /// <param name="id"></param>
        [ControllerAction]
        public void Index(int? id,string name,string sex)
        {
            ViewData["id"] = id;
            ViewData["name"] = name;
            ViewData["sex"] = sex;
            RenderView("Index");
        }      
    }






对应的Index视图:
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="MVCDemo.Views.Home.Index" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <h2>Welcome to my ASP.NET MVC Application!</h2>
    
    id=<%=ViewData["id"] %> <br/>
    name=<%=ViewData["name"] as string %><br/>
    sex=<%=ViewData["sex"] as string %>

</asp:Content>

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺得本文不錯(cuò),就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機(jī)會得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報(bào)

0/150
提交
取消