I’m reading percentages from a database, then use that number to create a bar showing visual progress. I need to do something like this on my aspx page:
<%
if (ViewData["width"] != null){
<div style="width: <%: ViewData["width"] %>px;"
</div>
}%>
Of course the above method doesn’t work, but hopefully you can see what im trying to achieve. How do i change style attributes dynamically in ASP.NET MVC?
You just wrote HTML in the middle of a code block. You need to put your HTML outside the code block.
Alternatively, you could switch to the Razor language which does away with all the
<% %>s and allows you to intersperse C# and HTML much easier. It looks like this: