mvc 預設訪問 Area 下控制器方法

來源:互聯網
上載者:User

標籤:style   blog   io   color   ar   使用   sp   div   on   

在MVC項目中經常會使用到Area來分開不同的模組讓項目結構更加的清晰。如果想網站開啟默開啟Area下的控制器時會出現以下的錯誤

“/”應用程式中的伺服器錯誤。未找到視圖“Index”或其母片視圖,或沒有視圖引擎支援搜尋的位置。搜尋了以下位置: ~/Views/Default/Index.aspx~/Views/Default/Index.ascx~/Views/Shared/Index.aspx~/Views/Shared/Index.ascx~/Views/Default/Index.cshtml~/Views/Default/Index.vbhtml~/Views/Shared/Index.cshtml~/Views/Shared/Index.vbhtml

 

解決方案:

public static void RegisterRoutes(RouteCollection routes){  routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  routes.MapRoute(      name: "Default",      url: "{controller}/{action}/{id}",      defaults: new { controller = "Default", action = "Index", id = UrlParameter.Optional},      namespaces:new string[]{"MVCUI.Areas.自己Area的名稱.Controllers"}      ).DataTokens.Add("Area","自己Area的名稱");}

 

超連結使用法:

return RedirectToAction("action", "controller", new { area = "area-name" });

 

<%= Html.ActionLink("超連結內容", "action", "controller", new { area = "area-name" }, null) %>

 

mvc 預設訪問 Area 下控制器方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.