shreya kumrawat

shreya kumrawat

  • NA
  • 24
  • 47.8k

Sequence contains more than one element in mvc

Feb 1 2015 1:46 PM
public ActionResult LogOn(GDCCollege.Models.StudentViewModel model, Attendance amodel)
        {
            if (ModelState.IsValid)
            {
                var v = db.Students.Where(a => a.Class.Equals(model.Class) && a.RollNo.Equals(model.RollNo)).FirstOrDefault();
                if (v == null)
                {
                    ViewBag.Message = "Invalid username and password";
                }
                else
                {
                    Session["LogedId"] = v.Id.ToString();
                    Session["LogedStudentName"] = v.StudentName.ToString();

                    var vm = db.Attendances.Single(u => u.StudentId == v.Id);
                   //var vm = (from a in db.Attendances where a.StudentId == v.Id select a).Single();
                    if (vm != null)
                    {
                        Attendance viewmodel = new Attendance();
                        viewmodel.Subject = vm.Subject;
                        viewmodel.PrevMonthAttendance = vm.PrevMonthAttendance;
                        viewmodel.Semester1Attendance = vm.Semester1Attendance;
                        viewmodel.Semester2Attendance = vm.Semester2Attendance;
                        return RedirectToAction("StudentProfile", viewmodel);
                    }
                    else
                    {
                        ViewBag.Message = "Try Again";
                    }
                }
            }
            return View(model);
        }


   There is an error occurred in this line where i highlight from green color..(sequence contain more than one element). so what do i do for it..I have multiple subjects attendence of single student.. and want o show on student profile view page.



Answers (1)