开发者

ASP.NET MVC 2 and sparkviewengine rendering single quotes to double quotes in html5 data- attribute

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":"initA开发者_开发问答larmZoneForm"}'><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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜