The name 'xyz' does not exist in the current context

后端 未结 7 1830
广开言路
广开言路 2020-12-11 13:45

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

相关标签:
7条回答
  • 2020-12-11 14:10

    This is a scoping problem. Anything inside of braces {} is defined as a block. Any variables defined in a block are only available within that block and are garbage collected when you exit the block.

    Don't define accountType inside the blocks in your if statement:

    string accounttype;
    
    if (programid == 0)
    {
        accounttype = "Membership";
    }
    else
    {
        accounttype = "Program";
    }
    
    0 讨论(0)
提交回复
热议问题