2016-04-05 76 views
1

我需要更改Razor視圖內某些靜態JSON數據的輸出。我想要做的是沿線Razor if語句與JSON

, actions: { // <- this is JSON curly bracker 
     listAction: '/Operations/Get' 
    @if(ViewBag.AllowInput) 
    { // <- this is Razor curly bracker 
    , createAction: '/Operations/Create' 
    , deleteAction: '/Operations/Delete' 
    } // <- this is Razor curly bracket 
} // <- this is JSON curly bracker 

但是,JSON標記會與剃刀大括號混爲一談。有沒有其他的語法,或者,我可能做一些真正愚蠢的錯誤?

+0

''。 – CodeCaster

回答

2

用戶<text>標籤或@:線轉義:

<text> 
, actions: { // <- this is JSON curly bracker 
     listAction: '/Operations/Get' 
</text> 
    @if(ViewBag.AllowInput) 
    { // <- this is Razor curly bracker 
    <text> 
    , createAction: '/Operations/Create' 
    , deleteAction: '/Operations/Delete' 
    </text> 
    } // <- this is Razor curly bracket 
<text> 
} // <- this is JSON curly bracker 
</text> 

, actions: { // <- this is JSON curly bracker 
     listAction: '/Operations/Get' 
    @if(ViewBag.AllowInput) 
    { // <- this is Razor curly bracker 
@: , createAction: '/Operations/Create' 
@: , deleteAction: '/Operations/Delete' 
    } // <- this is Razor curly bracket 
} // <- this is JSON curly bracker