7

In my case I pass data from controller to view using ViewBag.data and it binds correctly. Now what I want is to set the CSS width value. This is part of my view code.

  @foreach(var rat in @ViewBag.reviewRating)
  {
      <div class="Traveler-ratingsLine">
           <div class="Traveler-ratingsText">Excellent</div>
           <div class="Traveler-ratingsBar">
                 <div style="width: 100px" class="Traveler-ratingsBkg">
                      <div style="width: 32px;" class="Traveler-ratingsImg"></div>
                 </div>
           </div>
           <div class="Traveler-ratingsTextGreen">@rat.excellent</div>
     </div>
 }

So what I want to know is, is it possible to do something like this:

<div style="width: (@rat.someval)px;" class="Traveler-ratingsImg"></div>

I want to set the integer value from the controller like this for the CSS width.

1 Answer 1

10

Do it like this-

<div style="width: @(rat.someval+"px")" class="Traveler-ratingsImg"></div>

see here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.