简体   繁体   English

如何从helper方法返回字符串而不是html编码

[英]How to make returned string from helper method not html encoded

I'm using a C# helper method to check to see if the value of an input field should be prefilled or not. 我正在使用C#helper方法来检查输入字段的值是否应该预先填充。 When the value gets returned, however, any special characters have been replaced with html (ie: & is now & ). 但是,当返回值时,任何特殊字符都已替换为html(即:&现在是& )。 I'm looking for a way to change this back to the special characters (ie: change ab&c back to ab&c ). 我正在寻找一种方法将其更改回特殊字符(即:将ab&c更改回ab&c )。 I've tried HtmlDecode but it doesn't have any effect on the returned value. 我已经尝试过HtmlDecode,但它对返回的值没有任何影响。

The input field: 输入字段:

<input type="text" class=" form-textbox" id="input_4" name="q4_1Property" size="40" value="@Helpers.checkEmptyPreFill(queryinputvalue,"q4_1Property","ab&c")"/>

The helper method: 辅助方法:

@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
}

instead of @return_value 而不是@return_value

Try 尝试

new MvcHtmlString(return_value)

MvcHtmlString Represents an HTML-encoded string that should not be encoded again. MvcHtmlString表示不应再次编码的HTML编码字符串。

Look at msdn documentation for more details on MvcHtmlString() 有关MvcHtmlString()的更多详细信息,请查看msdn文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM