This is probably really basic in C#, but I looked around a lot to find a solution.
In my MVC controller\'s action method, I have an incoming routeid (programid
The problem is that you're defining your accounttype variable within the scope of your if and else block, so it's not defined outside of those blocks.
Try declaring your variables outside the if/else blocks:
string accounttype;
string URL;
if (programid == 0)
{
accounttype = "Membership";
}
else
{
accounttype = "Program";
}
if (results.Count() > 0)
{
URL = accounttype + "some text"
}
else
{
URL = accounttype + "some other text"
}
Or if your code is really this simple, just use the conditional operator:
string accounttype = programid == 0 ? "Membership" : "Program";
string URL = accounttype + (results.Any() ? "some text" : "some other text");