0
 I have a action method in studentController which filter students by classroomId

    public ActionResult ClassStudents(int classRoomId)
    {

        var students = st.GetAll().Where(s => s.ClassRoomID == classRoomId);

        var classroom = clr.GetByID(classRoomId);

        ViewBag.ClassRoomTitle = classroom.ClassRoomTitle;

        return View(students);
    }




when i input  /Student/ClassStudents/1

it give me a error as:

参数字典包含方法“System.Web.Mvc.ActionResult ClassStudents(Int32)”的不可空类型“System.Int32”的参数“classRoomId”的空条目

你能找到什么问题吗?谢谢

4

2 回答 2

0

代替

int classRoomId

int? classRoomId

如果你想处理空值或

int classRoomId = 0

如果你想有一个默认值而不是 null。

于 2013-04-27T19:45:51.810 回答
0

改变:

public ActionResult ClassStudents(int ClassRoomId)

public ActionResult ClassStudents(int? ClassRoomId)

这将使 ClassRoomId 可以为

于 2013-04-27T19:45:51.727 回答