3

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; 
1
  • You'd put it in your model (or the viewbag) and the cshtml would reference e.g. model.CircleMarginLeft when declaring the style info Commented Jun 1, 2019 at 7:28

1 Answer 1

1

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>
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.