MVC C#: System.InvalidOperationException

TK Lim

TK Lim

Oct 28 2014 6:16 PM

 I am new to MVC C#. I am building my project based on the MVC Music Store tutorial.

 I have the following code which throw the following error message during runtime. Please tell me how to handle the null value in my code.
[error message] 
 An exception of type 'System.InvalidOperationException' occurred in System.Core.dll but was not handled in user code
 [/error message]

public ActionResult SubCategory(int? s_catid)


var subcategories = db.Categories.Include("Sub_Categories").Single(s => s.C_Catid == s_catid);

return View(subcategories);


Thanks and regards.

Answers (2)