dropdownlist中的字符串包含<在itextshpar中

时间:2014-03-03 03:11:07

标签: c# drop-down-menu special-characters asp.net-mvc-5

我的应用程序是MVC5,我从下拉列表中获取字符串值,项目值<20%。

如果我尝试使用项目的值附加另一个字符串,则会剪切它。

例如:

string itemvalue = x; /*item value from the dropdownlist*/
string totalvalue = "score" + x;

在调试时,总值=得分<20%。但是,当我使用itextsharp HTMLWorker打印它时,我只得到分数!

3 个答案:

答案 0 :(得分:1)

<是一个html标记。您可以将其替换为&lt;

string itemvalue = x; /*item value from the dropdownlist*/
string totalvalue = "score" + x;
totalvalue.Replace("<","&lt;");
// you can use it now! ;)

其他事项: >应为&gt; 参考http://www.w3schools.com/html/html_entities.asp

答案 1 :(得分:0)

我认为使用它可以解决您的问题

string itemvalue = x; /*item value from the dropdownlist*/
string totalvalue = String.Format( "score{0}",x);

为什么不这样 从String

中删除%
 String.Format( "score{0}%",x);

OR

 String.Format( "score{0:00%}",x);

答案 2 :(得分:0)

我使用了HttpUtility.HtmlEncode(totalvalue),工作。