2015-09-20 52 views
-1

我遇到了@helper中的Action鏈接問題。 看到下面這條線@helper中的Url.Action不會引起事件

<a href="@Url.Action("Index","Category", new { id = item.Id })"> 

它根本不會引發事件。我在這裏做錯了什麼?

@helper ShowTree(IEnumerable<FrontEnd.Controllers.SharedController.Category> categories) 
      { 
        <ul id="@(Added == false ? "categories" : "")" class="parent-1"> 
         @foreach (FrontEnd.Controllers.SharedController.Category item in categories) 
         { 
          Added = true; 
          <li class="child-1 has-sublist"> 
           <a href="@Url.Action("Index","Category", new { id = item.Id })"> 
            @item.CategoryName 

            @if (item.Children.Count > 0) 
            { <span> 
             [@item.Children.Count] 
            </span> 
            } 

           </a> 

          @if (item.Children.Any()) 
          { 
            @ShowTree(item.Children) 
          } 
          </li> 
         } 
        </ul> 
      } 
+1

什麼「事件」你指的是?要轉到您的Action方法中指定的另一個URL? –

+0

你的控制器被擊中了嗎?你有任何錯誤或例外嗎?我所指的控制器是「Listing」控制器(正如你的Url.Action所指定的) –

+0

@Ahmedilyas是的,我的意思是,我的意思是發給控制器。 e.preventDefault();包含的JavaScript阻止了請求。 – OrElse

回答

0

確定。剛剛找到治療方法。

JavaScript是阻塞請求控制器..

$('#categories > li a').click(function(e){ 
      if($(this).parent().hasClass('has-sublist')) { 
       e.preventDefault(); 
      }.... 
................. 
+1

您的問題中沒有任何內容表明任何JavaScript!刪除問題 - 它不適用於任何人 –

+0

@StephenMuecke如果我知道JavaScript阻止了這一點,我不會問。無論如何,我怎麼能刪除這個? – OrElse

+0

點擊問題底部的刪除鏈接:) –

0

你試過類似下面的東西嗎?

@Html.ActionLink(item.CategoryName, "Index", "Listing", new { id = item.Id }, null, null) 

https://msdn.microsoft.com/en-us/library/dd460522(v=vs.118).aspx

+1

我認爲你的意思是@ @ Html.ActionLink()' –

+0

@StephenMuecke - 好的接收。確實是的。 –

+1

這和OP完成它的詳細方式沒有區別。 – DavidG

相關問題