Devy
Devy

Reputation: 703

Change css dynamically from controller

I'm new with ASP.NET MVC, at the cshtml I have some style:

 .circle {
     border: 2px solid red;
     background-color: #FFFFFF;
     height: 100px;
     border-radius:50%;
     width: 100px;
 }

<div class="circle"></div>

And I want to change the circle position from the controller, I can I achieve that? In the controller I need something like:

circle.MarginLeft = 120; 

Upvotes: 3

Views: 639

Answers (1)

habib
habib

Reputation: 2446

You can use your model or ViewBag.

In controller pass your data into an object like circle.MarginLeft = 12 or use ViewBag['marginLeft'] = 12

and in your .cshtml file set

<div class="circle" style="margin-left:@ViewBag.marginLeft"></div>

or

<div class="circle" style="margin-left:@Model.marginLeft"></div>

Upvotes: 1

Related Questions