1

I need to change output for some static JSON data within a Razor view. What I'm trying to do is along the lines of

, 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

However, JSON markup gets messed with Razor curly brackets. Is there any alternative syntax, or, perhaps, do I do something really stupidly wrong?

1 Answers1

5

User <text> tag or @: line escaping:

<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>

or

, 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
teo van kot
  • 12,350
  • 10
  • 38
  • 70