문제

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?

도움이 되었습니까?

해결책

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>

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top