2016-08-17 60 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', –