2015-11-01 120 views
0

剛開始鑽研路線Areas。我在嘗試一些基本的東西之前,我很喜歡。當我在地址欄中輸入物理路線時,效果很好。但是,當我嘗試使用@Url.Action@Html.ActionLink創建鏈接時,MVC無法弄清楚如何計算正確的路線。無法爲我的MVC區域呈現正確的網址

打字的工作原理: 所以,我所知道的路線是正確設置...

http://localhost:51515/intro/tutorials/one 

我的控制器的樣子:
同樣,這解決了正確的,當我鍵入它地址欄...

[RouteArea("intro")] 
[RoutePrefix("tutorials")] 
[Route("{action}")] 
public class IntroTutorialsController : Controller 
{ 
    public ActionResult One() 
    { 
     var path = @"~/Views/tutorials/intro/one.cshtml"; 
     return View(path); 
    } 
} 

MY SAD嘗試以該URL:
顯然,問題是在這裏...

@Html.ActionLink("intro", "one", "tutorials", new { Area = "intro" }, null) 
<a href="@Url.Action("one", "tutorials", new { Area = "intro" })">One</a> 

這些沒有決心和/或無義......

一個側面說明:
如果我hand-type網址進入鏈接...他們的工作。

例如:

  • HREF = 「/介紹/教程/一個」

回答

0

抱歉地回答我的問題...

顯然,Html.ActionLinkUrl.Action命令不會考慮您可能放在控制器上的任何屬性前綴。因此,您仍然必須以普通格式輸入您的動作&控制器名稱...然後...插入您的area

這爲我工作...

@Url.Action("one", "introtutorials", new { Area = "intro" })