我有类用户在我的项目,并有模型UserRow(用于显示用户视图) 它UserRow添加检查控制器
using System;
namespace Argussite.SupplierServices.ViewModels
{
public class UserRow
{
public Guid Id { get; set; }
public string FullName { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public int Status { get; set; }
public int Role { get; set; }
public Guid SupplierId { get; set; }
public bool ActionsAllowed { get; set; }
public bool MailResendRequired { get; set; }
}
}
,我需要在我的控制器中添加检查,如果ActionsAllowed
[HttpPost]
public ActionResult Unlock(Guid id)
{
var user = Context.Users.Find(id);
if (user == null)
{
return Json(CommandResult.Failure("User was not found. Please, refresh the grid and try again."));
}
var checkActionsAllowed = Context.Users.AsNoTracking()
.Select(e => new UserRow
{
Id = e.Id,
ActionsAllowed = e.ActionsAllowed
};
if (checkActionsAllowed == true)
{
user.Status = UserStatus.Active;
return Json(CommandResult.Success(string.Format("User {0} has been unlocked.", user.FullName)));
}
else return;
}
,但我在else return;
与ActionsAllowed = e.ActionsAllowed
和
遇到错误请帮我解决这个问题。
是的,我有'UserRow'属性'ActionsAllowed',但没有它'User',但我不知道如何让用户使用ID在控制器检查。而在其他情况下,我什么也得不到。 – Heidel
你不能只是返回一个操作方法 - 必须发送某种响应。一个简单的'return false'可能起作用,尽管我会想出一个更有意义的响应代码,或者抛出一个'HttpException'。请记住,您正在响应HTTP请求。 –