Why does Razor not like this?

后端 未结 5 1457
闹比i
闹比i 2020-12-18 20:32

Ive got a mega annoying problem I have a view with:

@{

        if(ViewBag.Section == \"Home\")
        {
           
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-18 21:00

    You can use the same construct when you wrap your div's inside element like:

    @if (ViewBag.Section == "Home")
    {
        
    } else {

    Or you use razor syntax @: like

    @if (ViewBag.Section == "Home")
    {
        @:
    } else { @:

    But for your current situation I would prefer Ron Sijm's solution:

    @{
    var divName = ViewBag.Section == "Home" ? "headerfrontPage" : "header";
    }
    
    

提交回复
热议问题