hncl
hncl

Reputation: 2295

String from dropdownlist contains < in itextshpar

My application is MVC5, I get a string value from a dropdownlist, the item value is <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%. However when I print it using itextsharp HTMLWorker I only get score!

Upvotes: 0

Views: 182

Answers (3)

Shamim
Shamim

Reputation: 444

the < is an html tag. you can replace it with &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;
refer to http://www.w3schools.com/html/html_entities.asp

Upvotes: 1

hncl
hncl

Reputation: 2295

I used HttpUtility.HtmlEncode(totalvalue), worked.

Upvotes: 0

Mohit
Mohit

Reputation: 11324

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);

Upvotes: 0

Related Questions