2016-08-17 136 views
0

我有問題,在我上面的代碼中,兩個第一頁以完美的方式工作,但最後一個只顯示一個頁面,只有一行代碼細節。我需要幫助!!html actionlink的屬性

@if (((RegisteredUser)Session["User"]).IsExpert) 
{ 
<li>@Html.ActionLink("Área técnica", "Index", "Dashboard", new { area = "Expert" }, null)</li> 
} 
@if (((RegisteredUser)Session["User"]).IsServiceDeskAdmin) 
{ 
<li>@Html.ActionLink("Área de administração", "Index", "Dashboard", new { area = "Administration" }, null)</li> 
} 
@if (((RegisteredUser)Session["User"]).IsExpert) 
{ 
<li>@Html.ActionLink("Perfil", "Index", "PerfilController", new { area = "Perfil" }, null)</li> 
} 

上面的代碼是.cs文件。由於

 using System; 
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Net; 
    using System.Net.Http; 
    using System.Web; 
    using System.Web.Mvc; 

    namespace Fcebi.ServiceDesk.WebPlatform.Controllers 
    { 
     public class PerfilController : Controller 
     { 

    // GET: Perfil 
    protected override void OnActionExecuted(ActionExecutedContext filterContext) 
    { 
     base.OnActionExecuted(filterContext); 
     Fcebi.ServiceDesk.WebPlatform.Areas.Expert.ExpertAuth.DoAuth(Session, Request, filterContext, Url); 
    } 
    public ActionResult Index(String Id) 
    { 
     // Id = api da tabela User 
     Id = "Id7dkSro7Qh"; 
     if (String.IsNullOrEmpty(Id) || String.IsNullOrWhiteSpace(Id)) 
     { 
      return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest, "O ID do utilizador tem de ser definido"); 
     } 
     else 
     { 
      try 
      { 

       RegisteredUser U = RegisteredUser.FindByAPI(Id); 

       var JsonToReturn = new 
       { 
        Name = U.Name, 
        Departamento = U.Department, 
        Email = U.Email, 
        signature=U.Signature 
       }; 
       return Json(JsonToReturn, JsonRequestBehavior.AllowGet); 
      } 

      catch (ServiceDeskException Ex) 
      { 
       return new HttpStatusCodeResult((int)Ex.ErrorId, Ex.Message); 
      } 
      catch (Exception Ex) 
       { 
       new ServiceDeskException(ServiceDeskException.ErrorList.OTHER, Ex); 
       return new HttpStatusCodeResult(System.Net.HttpStatusCode.InternalServerError, Ex.Message); 
       } 

      } 
     } 
    } 
    } 
+0

你的措詞不清楚。你的意思是_link_不能正確顯示,或者點擊link_呈現的_page不能正確顯示?我不知道你的意思是「只有一行代碼細節」 – ADyson

+0

鏈接不工作100%,頁面沒有重定向,當我強制鏈接去頁面只出現一行信息與用戶信息,我想顯示配置良好的頁面,我複製並粘貼工作頁面的代碼,所以更改了變量和我想顯示的內容 –

+0

actionlink的呈現html是什麼樣子的?這是否對應於應用程序中的真實控制器和操作? – ADyson

回答

1

試着將

@Html.ActionLink("Perfil", "Index", "PerfilController", new { area = "Perfil" }, null) 

@Html.ActionLink("Perfil", "Index", "Perfil", new { area = "Perfil" }, null) 

我不認爲你應該追加 「控制器」 - MVC會做得出來。

其次,您的.cs索引方法正在返回JSON。因此,如果您在瀏覽器中執行該操作,則只會將JSON視爲文本。它沒有返回一個網頁。所以你在做什麼創建一個鏈接沒有多大意義 - 它看起來像它被設計爲通過Ajax調用。

+0

他重定向到另一個頁面。 –

+0

@ThiagoSchettiniMari我不明白。 「他重定向到另一頁」?誰幹的?它在哪裏重定向?附:重申您的其他評論我不會向陌生人發送我的電子郵件地址,並且應有盡有的尊重,對不起。也許粘貼PerfilController.cs與索引方法到你的問題。你的路由配置也是有用的。最後,我再次要求查看動作鏈接變成的__指定的HTML_ :-) – ADyson

+0

這是我在索引中的代碼。@ { ViewBag.Title =「Perfil」; Layout =「〜/ Views/Shared/_Layout.cshtml」; ServiceDeskConfig Config = new ServiceDeskConfig(); RegisteredUser User =(RegisteredUser)Session [「User」]; ('click',function(){SubmitPerfil();});}();}() });函數SubmitPerfil()如果(ServiceDeskFormValidator())var Data = new FormData(); $ .ajax({url:'@ Url.Content(「〜」)/ Perfil/Index', –