我有一个新的sylius标准应用程序中的这个控制器,我试图从容器访问一些服务,但容器始终为空。
根据Symfony Docs,你需要让控制器容器知道的就是扩展Controller类,正如我所做的那样。
public class Student
{
public Student()
{
this.isPassive = false;
Lessons = new HashSet<Lesson>();
}
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName { get { return FirstName + " " + LastName; } }
public string Mail { get; set; }
public string Password { get; set; }
public Nullable<int> LessonCredit { get; set; }
public bool isPassive { get; set; }
public int AccountTypeID { get; set; }
//Navigation Property
public virtual AccountType AccountType { get; set; }
public virtual ICollection<Lesson> Lessons { get; set; }
}
public class Lesson
{
public Lesson()
{
Students = new HashSet<Student>();
this.isPassive = false;
}
public int ID { get; set; }
public string Name { get; set; }
public int Credit { get; set; }
public bool isPassive { get; set; }
public Nullable<int> TeacherID { get; set; }
//Navigation Property
public virtual Teacher Teacher { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
[HttpPost]
public ActionResult LessonSelection(int[] LessonChecked)
{
int loginStudentId = Convert.ToInt32(Session["PersonId"]);
Student loginStudent = _studentBLL.Get(loginStudentId);
for (int i = 0; i < LessonChecked.Length; i++)
{
Lesson lesson = _lessonBLL.Get(LessonChecked[i]);
loginStudent.Lessons.Add(lesson);
_studentBLL.Update(loginStudent);
}
return View();
}
我需要做任何其他配置吗?欢迎任何帮助。