我的Models
文件夹
namespace School.Models
{
public enum Grade
{
A, B, C, D, F
}
public class Enrollment
{
public int EnrollmentID { get; set; }
public int CourseID { get; set; }
public int StudentID { get; set; }
public Grade Grade { get; set; }
public virtual Course Course { get; set; }
public virtual Student Student { get; set; }
}
}
我想在Grade属性中进行授权,因此当Admin中的Admin Role日志可以修改成绩值时,当用户角色登录时,用户无法修改属性并且只能看到成绩的值(以及如何为成绩属性设置默认值
答案 0 :(得分:0)
在更新成绩的控制器操作上添加authorize属性。
[Authorize(Roles = "user or group")]
public IActionResult UpdateGrade()
{
//update grade here
return View();
}
在类构造函数中设置默认等级。
public class Enrollment
{
public Enrollment()
{
Grade = Grade.B;
}
public int EnrollmentID { get; set; }
public int CourseID { get; set; }
public int StudentID { get; set; }
public Grade Grade { get; set; }
public virtual Course Course { get; set; }
public virtual Student Student { get; set; }
}