【问题标题】:html actionlink attributeshtml actionlink 属性
【发布时间】:2016-08-17 09:26:46
【问题描述】:

我有一个问题,在我上面的代码中,前两个页面以完美的方式工作,但最后一个页面只显示一个页面,其中只有一行代码细节。我需要帮助!!

 @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);
               }

           }
        }
     }
  }

【问题讨论】:

  • 您的措辞不清楚。您的意思是 链接 没有正确显示,或者 通过单击链接呈现的页面 没有正确显示?我不知道你所说的“只有一行代码细节”是什么意思
  • 链接不工作100%,页面没有重定向,当我强制链接到页面时,只出现一行用户信息,我想显示配置良好的页面,我复制并粘贴了有效页面的代码,因此更改了变量和我想要显示的内容
  • actionlink 渲染的 html 是什么样的?这是否对应于您的应用程序中的真实控制器和操作?
  • 这就像一个空白页面,其中一行信息,而不是,真正的控制器是一个带有默认布局和我需要显示的信息的html页面。但是链接上的两个页面(“专家”和“管理”)是有效的
  • 不,我问的是 actionlink 呈现的 html 是什么样的。我在问它是否绝对指向正确的地方?

标签: c# html actionlink html.actionlink


【解决方案1】:

尝试改变

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

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

我认为您不应该附加“控制器” - MVC 会解决的。

其次,您的 .cs 索引方法返回 JSON。因此,如果您在浏览器中执行该操作,您只会将 JSON 视为文本。它没有返回网页。因此,您正在做什么创建指向它的链接并没有多大意义 - 它看起来像是被设计为通过 Ajax 调用的。

【讨论】:

  • 他重定向到另一个页面。
  • @ThiagoSchettiniMari 我不明白。 “他重定向到另一个页面”?谁干的?它重定向到哪里?附言关于您的其他评论,恕我直言,我不会将我的电子邮件地址透露给陌生人,对不起。也许将带有 Index 方法的 PerfilController.cs 粘贴到您的问题中。您的路线配置也很有用。最后,我将再次要求查看 ActionLink 变成的 渲染 HTML :-)
  • 那是我在索引中的代码。@{ ViewBag.Title = "Perfil";布局 = "~/Views/Shared/_Layout.cshtml"; ServiceDeskConfig 配置 = 新的 ServiceDeskConfig(); RegisteredUser 用户 = (RegisteredUser)Session["User"]; }
    Dados do Utilizador @User.Name
  • 是什么?没看到
  • 请粘贴到问题中(按照我的要求)。 cmets 中的大块代码不可读:-)
猜你喜欢
  • 2011-05-05
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 2010-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多