I left some code out for brevity…
int id = Convert.ToInt32(Page.RouteData.Values["id"]);
var q = db.Categories.SingleOrDefault(x => x.categoryID == id);
ddlCategory.SelectedValue = q.parentID == 0 ? 0 : id.ToString();
I get the error:
Type of conditional expression cannot be determined because there is no implicit conversion between ‘int’ and ‘string’ (It’s talking about the id.ToString() piece.)
I tried Convert.ToString() and I tried putting (string) infront of id but that didn’t work.
Because the two return values of the ternary are not of the same type — one is
intand the other isstring. 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.
objectwill do fine.