I have created an object in a controller method which I am using in a view but it is giving me exception. Please tell me what I am doing wrong.
Here is my debugging result.
And here is my function to create the object.
public object GetResult(int CourseId, int Reg_Id, int RollNo, string name, string Description)
{
var result = db.Results.Where(r => r.Course_Id == CourseId && r.Student_Reg_Id == Reg_Id && r.Description == Description).Single();
var resultData = new {
reg_Id = Reg_Id,
Roll = 0,
Name = "",
Obtained = "",
Total = ""
};
if (result != null)
{
resultData = new {
reg_Id = Reg_Id,
Roll = RollNo,
Name = name,
Obtained = result.Obtained_Marks.ToString(),
Total = result.Total_marks.ToString()
};
}
else
{
resultData = new {
reg_Id = Reg_Id,
Roll = RollNo,
Name = name,
Obtained = "Not Available",
Total = "Not Available"
};
}
return resultData;
}