MVC 之 初識(一)

來源:互聯網
上載者:User

標籤:mapr   代碼   如何   localhost   str   lte   iis   檔案內容   filters   

建立一個mvc項目,在項目中會startup.cs檔案,startup檔案主要是將項目尋找一個宿主

過去,項目一般都是寄宿在iis上的,通過owin可以寄宿到不同的宿主。

可以關閉owin:<appSettings><add key="owin:............"> </>(可以百度)

 

如何建立視圖,調用方法:

1/建立控制器firstController,在mvcview中會自動產生一個first的檔案夾

2/在控制器中會有一個預設的 ActionrResult index ,滑鼠在此右擊--添加視圖

3/同理:在控制器中直接寫一個方法,然後訪問路徑:localhost/控制器名/方法名

 public void responseWrite(){            this.Response.Write("一點半");            this.Response.End(); } public string getStr(){            return "測試";}當執行這兩個方法時,會發現頁面都能出現資訊,其實所有返回的資料都是通過response來輸出到頁面上的

 

從Global.ascs(全域設定檔)檔案認識mvc

這個Global檔案什麼時候被訪問呢?:網站第一次啟動的時候會率先執行

Global檔案內容:public class MvcApplication : System.Web.HttpApplication    {        protected void Application_Start()        {           1. AreaRegistration.RegisterAllAreas();           2. FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);           3. RouteConfig.RegisterRoutes(RouteTable.Routes); //路由           4. BundleConfig.RegisterBundles(BundleTable.Bundles);        }    }

 

 

3.這個檔案是mvc的路由註冊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 }            );        }
mvc是通過路由來存取碼的

 

MVC 之 初識(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.