简体   繁体   中英

adding code snippet to Razor (MVC 3)

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM