我正在做一个维护页面,人们可以在其中存储资源文件中将要说的内容的描述,此时在要求中他们甚至不知道文本是纯文本还是具有类似<a></a>. 所以在这一点上,我必须假设情况会如此。这个proyect是在VS2010的Webforms framework 3.5中制作的。为了简单起见,我将揭示相关部分:<article> <img alt="an image" src="Images/logo.jpg"/> <h2>Site under Maintenance</h2> <div> <p id="Description"></p> </div></article><script src="Includes/jquery-1.12.3.min.js" type="text/javascript"></script><script type="text/javascript"> $(document).ready(function () { $.ajax({ type: "GET", url: "MaintenanceSite.aspx/GetMaintenanceDescription", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { $("#Description").text(msg.d); } }); });</script>后端:[WebMethod][ScriptMethod(UseHttpGet = true)]public static string GetMaintenanceDescription(){ string mensaje = HttpUtility.HtmlEncode(Resources.MaintenanceDescription); return mensaje;}问题是,我在我的段落中收到了这个:<To href="">Contact Us</a>(没有空格,因为堆栈溢出正在正确解析 html)。我错过了什么?
1 回答
慕的地6264312
TA贡献1817条经验 获得超6个赞
这里有两个问题。首先,您需要删除HtmlEncode()
C# 逻辑中的调用以返回纯 HTML 字符串。其次,您需要使用 jQuery 的html()
方法来显示它而不是text()
,因为后者将再次对 HTML 进行编码。
string mensaje = Resources.MaintenanceDescription;
$("#Description").html(msg.d);
- 1 回答
- 0 关注
- 62 浏览
添加回答
举报
0/150
提交
取消