I left some code out for brevity...
int id = Convert.ToInt32(Page.RouteData.Values[\"id\"]);
var q = db.Categories.SingleOrDefault(x => x.categoryID == id);
Because your are trying to make the ternary operator evaluate to either an int (0
) or a string (id.ToString()
). Replace the 0
with "0"
.
Because the two return values of the ternary are not of the same type -- one is int
and the other is string
. The compiler cannot deduce what the ternary expression's return type is.
Solution: Return the same type from both branches, or cast one of them to a base of the other. object
will do fine.