简体   繁体   English

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

[英]String from dropdownlist contains < in itextshpar

My application is MVC5, I get a string value from a dropdownlist, the item value is <20%. 我的应用程序是MVC5,我从一个下拉列表中获得了一个字符串值,项目值<20%。

If I try to append another string with the value of the item it cuts it. 如果我尝试在另一个字符串后附加项目的值,则会将其剪切。

for example: 例如:

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

on debug, the total value = score <20%. 在调试时,总值=得分<20%。 However when I print it using itextsharp HTMLWorker I only get score! 但是,当我使用itextsharp HTMLWorker打印它时,我只会得到分数!

the < is an html tag. <是html标记。 you can replace it with &lt; 您可以将其替换为&lt;

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

other things: > should be &gt; 其他情况: >应该&gt;
refer to http://www.w3schools.com/html/html_entities.asp 请参阅http://www.w3schools.com/html/html_entities.asp

I think using this will solve your issue 我认为使用此方法可以解决您的问题

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

Why not this remove % from String 为什么不从字符串中删除%

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

OR 要么

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

我使用HttpUtility.HtmlEncode(totalvalue),有效。

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

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