我有一个问题,在上面的代码中,两个第一页以完美的方式工作,但最后一页只显示一页只有一行代码细节。我需要帮助!!
@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 :(得分:1)
尝试更改
@Html.ActionLink("Perfil", "Index", "PerfilController", new { area = "Perfil" }, null)
到
@Html.ActionLink("Perfil", "Index", "Perfil", new { area = "Perfil" }, null)
我认为你不应该追加“控制器” - MVC会解决这个问题。
其次,您的.cs Index方法返回JSON。因此,如果您在浏览器中执行该操作,您只需将JSON视为文本。它没有返回网页。所以你正在创建一个链接到它没有多大意义 - 它看起来像是通过Ajax调用。