0

I'm having a problem with adding a json value as a data-attribute in a html5 page.

We use the spark view engine (v1.5) in our asp.net mvc 2.0 website.

The following viewcode:

<a href='${Url.Action("edit", new { id = vehicle.VehicleId })}' title='Bewerken' class='dialog dialog-edit' data-dialogoptions='{"beforeOpen":"initAlarmZoneForm"}'><span class="silk-icon silk-icon-page-edit"></span></a>

is being rendered as:

<a href="/Alarm/AlarmZone/edit/4" title="Bewerken" class="dialog dialog-edit" data-dialogoptions="{"beforeOpen":"initAlarmZoneForm"}"><span class="silk-icon silk-icon-page-edit"></span></a>

note the enclosing double quotes in data-dialogoptions

A single quote is required to generate a valid json-string in the data-dialogoptions attribute.

Does anyone know what is causing this behavior and how I can change or work around it?

Rik
  • 483
  • 3
  • 12

1 Answers1

2

Although this is more of a workaround than an answer, you don't really need to get spark to render single quotes. You could use &#x22; escape character which JSON.parse seems to parse correctly.

Here's a really basic example of it running.


Looks like you're seeing this behavior due to a bug/feature in the Spark view engine.


As of version 1.6, this "feature" was "fixed". Spark should now properly preserve single/double quotes.

Community
  • 1
  • 1
Roman
  • 19,581
  • 6
  • 68
  • 84