0

I read the docs and apparently this should be acceptable:

    @{
    string isDisplay = "";    
    if (@ViewBag.Name == "" || @ViewBag.Name == null)
    { 
        isDisplay ="display:none;";
    }
}

it's giving me a compliation error however though:

this is the error: Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1501: No overload for method 'Write' takes 0 arguments

any ideas?

1 Answer 1

2

I don't have the compiler on hand, but this should be better

   @{
    string isDisplay = "";    
    if (ViewBag.Name == "" || ViewBag.Name == null)
    { 
        isDisplay ="display:none;";
    }

No need for the @ sign in a Razor Block

Sign up to request clarification or add additional context in comments.

2 Comments

still getting the same compilation error. the row that's highlighted is the first @{
turns out it didn't work inside my custom form html helper method...when I put the code outside, it worked fine. Thanks for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.