当字符串从后面的代码传递到 Web 表单时如何显示分号?

How to display cent sign when the string is passed to web form from code behind?

我在代码隐藏中有一个方法,returns 一个字符串形式的价格

public string GetPrice(){
    //some code
    price = "50¢";
    return price;
}

在 aspx 页面中我这样使用它:

<%: MoneyHelper.GetPrice() %> 

它不显示分符号,尝试了不同的分字符编码,但它仍然是一个普通字符串。如何正确显示?

因为您已经有了 html 编码,所以您需要使用 <%= MoneyHelper.GetPrice() %>

或者在您的方法中使用 unicode 分符号更好。

public string GetPrice(){
    //some code
    price = "50¢";
    return price;
}

你能试试这个代码吗
字符串 cent = "50\u00A2";