I am trying to make my razor view a little more dynamic. I am trying to set an inline style to TDs in a table.
I made the string:
@{
double width = 100 / 5;
String widthStyleString = String.Format("style=\"width: {0}%;\"", width);
}
That worked out great when I tested it as plain text. I got:
style="width: 20%;"
However when I tried to put it into an HTML element I got this:
<td class="table--td" style=""width:" 20%;"="">Some Value</td>
How would I get it to not parse the " as the entity? (it would not let me type & quot without making it into an actual ")
update:
This is still a good way to do HTML atrributes. However in THIS instance, it is a style tag, the people commenting are right; it is better to do it in css and not the logic. If you have this exact issue (style attribute), the stack post below will help you. Otherwise, Html.Raw() is good.
Equal sized table cells to fill entire width of holding table
That link will solve this issue if you DO NOT need to worry about IE8 and below. Otherwise you still have to hardcode the width percentage in your css.