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

坚强是说给别人听的谎言 提交于 2019-12-12 10:22:54

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5859199/asp-net-mvc-2-and-sparkviewengine-rendering-single-quotes-to-double-quotes-in-ht

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!