2012-08-02 24 views
0

我正在教自己的asp.net.net mvc3。 我想創建一個用戶帳戶頁面,其中有3個標籤 - 說YourAddress,YourPhotos和YourProfile。使用不同的頁面處理選項卡內的子標籤-asp.netnet mvc 3

的第三個標籤(YourProfile)中有2個子選項... ChangeDetails和DeactiaveAccount。

他們都是動態頁面,因此我希望他們繼續作爲單獨的頁面。

基本上網址如下:

localhost/MyHome/YourAddress 
localhost/MyHome/YourPhotos 
localhost/MyHome/YourProfile/ChangePassword 
localhost/MyHome/YourProfile/DeactivateAccount 

(按照要求,我已經改變了通用TAB1,TAB2等在真實世界場景中的東西)

我打算做這樣的事情:

public class MyHomeController : Controller 
    { 
     // 
     // GET: /MyHome/Tab1 

     public ActionResult Tab1() 
     { 
      return View(); 
     } 

     // 
     // GET: /MyHome/Tab2 

     public ActionResult Tab2() 
     { 
      return View(); 
     } 

     // 
     // GET: /MyHome/Tab3 

     public ActionResult Tab3() 
     { 
      return View(); 
     } 
    } 

如何處理YourProfile的子選項卡?如何在控制器中調用控制器?

什麼是實現這一目標的最佳途徑。

感謝

+0

你能提供一個真實的世界場景選項卡將有什麼? – Shyju 2012-08-02 19:06:46

+0

使用jquery。這裏是一個例子http://www.stackdotnet.com/2011/11/taband-subtab-in-mvc-by-using-jquery.html – cshemby 2012-08-02 19:22:04

回答

1

有在你的控制器每個標籤項單獨的操作方法。

public class MyHomeController : Controller 
{ 
    public ActionResult YourAddress() 
    { 
    return View(); 
    } 
    public ActionResult YourPhotos() 
    { 
    return View(); 
    } 
    public ActionResult YouProfile() 
    { 
    return VieW(); 
    } 
    public ActionResult ChangePassword() 
    { 
    return View(); 
    } 
    public ActionResult DeActivate() 
    { 
    return View(); 
    } 
} 

對於子選項卡的內容,定義在Global.asax

routes.MapRoute("ChangePass","YourProfile/ChangePassword", 
         new { controller="MyHome", action="ChangePassword" }); 
routes.MapRoute("DeActivate","YourProfile/DeActivate", 
         new { controller="MyHome", action="DeActivate" }); 
routes.MapRoute(
      "Default", 
      "{controller}/{action}/{id}", 
      new { controller = "Home", action = "Index", id = UrlParameter.Optional }); 

始終使用Url.Action HTML輔助方法來呈現一個動作方法的路徑路由。

<div id="tabs"> 
    <ul> 
     <li><a href="@Url.Action("YourAddress","MyHome")">Address</a></li> 
     <li><a href="@Url.Action("YourPhotos","MyHome")">Photos</a></li> 
    </ul> 
</div> 
+0

感謝這一點。我會試試這個。如何使用「區域」? – Tripping 2012-08-02 19:34:55

+0

@Tripping:我會用區域,如果functinality是entirly不同。(例如:普通用戶是Ecom門戶和管理員用戶是Ecom門戶) – Shyju 2012-08-02 19:38:20

+0

感謝@shyju ......就像一個魅力,但我還是不明白是怎麼路由當我點擊鏈接時會起作用。 – Tripping 2012-08-02 19:46:44

相關問題