Question

I´m working on a MVC3 project.

I already have a decimal value into a ViewData["nReceived"] calculated in the controller. After that the controller calls to Index view.

I'm able to display it on Index view outside of a element

<div class="bar bar-success" style="width: 42%;">Received  @ViewData["nReceived"]</div>

but I need to use this value as a property of element replacing the width percentage.

I tried this with no success:

<div class="bar bar-success" style="width: @ViewData["nReceived"]%;">Received</div>

and also this:

@ViewContext.Writer
    .Write("<div class=\"bar bar-success\" style=\"width: @ViewData["nReceived"]%;">")

Any ideas on how to get it working?

Was it helpful?

Solution

This should work use @()

<div class="bar bar-success" style="width:@(ViewData["nReceived"])%;">Received</div>

Also Since you are using MVC3, you can try ViewBag as well

<div class="bar bar-success" style="width:@(ViewBag.nReceived)%;">Received</div>

OTHER TIPS

style='width: @Html.Raw(ViewData["nReceived"])' you're breaking your quotes and you need this to render out a little differently here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top