[英]How to make Razor not display special characters as html
The page I'm working on displays content from a database in readonly input box. 我正在处理的页面显示来自只读输入框中的数据库的内容。 My problem is that it's displaying any special characters as the html code (ie: & displays as &).
我的问题是它显示任何特殊字符作为html代码(即:&显示为&)。 How do you get the code to display properly?
如何让代码正确显示?
I'm using QuerySingle to connect to the database, don't know if that makes a difference. 我正在使用QuerySingle连接到数据库,不知道这是否有所作为。 I'm new to using Razor.
我是新手使用Razor。 Any help is much appreciated.
任何帮助深表感谢。
Code in question: 有问题的代码:
var queryloan = "SELECT * FROM loans WHERE LoanId = @0";
var queryloandata = db.QuerySingle(queryloan, queryformstatus_submitted.doc_loanid);
<form class="jotform-form" action="submit-form.cshtml?isadmin=@(isadmin)&loanid=@(loanid)" method="post" name="form_30905105572145" id="30905105572145" accept-charset="utf-8">
<input type="hidden" name="formID" value="30905105572145" />
<input type="hidden" name="doc_id" value="@doc_id" />
<div class="form-all">
<ul class="form-section">
<li id="cid_3" class="form-input-wide">
<div class="form-header-group">
<h2 id="header_3" class="form-header">
Borrower Sources & Uses Summary
</h2>
@if (queryformstatus_submitted.doc_approval == "Pending Approval" || queryformstatus_submitted.doc_approval == "Approved")
{
<text><br />
<br />
<div class="error">
This form has already been submitted and cannot be edited. It is for reference only.</div></text>
}
@if(userid != queryformstatus_submitted.doc_userid){
<text><br/><br/><div class="error">You may not edit this form. It is for reference only.</div></text>
}
</div>
</li>
<li class="form-line" id="id_4">
<label class="form-label-left" id="label_4" for="input_4">
1. Property Name:
</label>
<div id="cid_4" class="form-input">
<input type="text" class=" form-textbox" id="input_4" name="q4_1Property" size="40" value="@Helpers.checkEmptyPreFill(queryinputvalue,"q4_1Property",queryloandata.LoanName)"/>
</div>
</li>
I'm not sure but I believe it may be something in this helper function that's causing the html code: 我不确定,但我相信它可能是这个辅助函数中导致html代码的东西:
@helper checkEmptyPreFill(IEnumerable<dynamic> queryinputvalue, string field_id, string defaultval, int cloned = 0) {
var reqValue = queryinputvalue.FirstOrDefault(r => r.field_name.Equals(field_id));
var return_value = "";
if(reqValue != null){
return_value = reqValue.field_data;
} else {
return_value = defaultval;
}
if(cloned == 1){
return_value = "";
}
@return_value
} }
The razor helper returns a HelperResult
object so you'll have to convert it to a string before you can call HtmlDecode
on it. 剃刀助手返回一个
HelperResult
对象,因此您必须HelperResult
其转换为字符串,然后才能在其上调用HtmlDecode
。 Replace: 更换:
@Helpers.checkEmptyPreFill(queryinputvalue,"q4_1Property",queryloandata.LoanName)
with the following: 以下内容:
@HttpUtility.HtmlDecode(Helpers.checkEmptyPreFill(queryinputvalue,"q4_1Property",queryloandata.LoanName).ToString())
I would also suggest that you move some of the logic and data access code out of your view and into a controller but this should give you the result that you'e after. 我还建议你将一些逻辑和数据访问代码移出你的视图并进入一个控制器,但这应该会给你以后的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.