我是 ASP.NET MVC 的新手,在 cshtml 上我有一些风格:
.circle {
border: 2px solid red;
background-color: #FFFFFF;
height: 100px;
border-radius:50%;
width: 100px;
}
<div class="circle"></div>
我想通过 Controller 更改圆圈位置,我可以实现吗?在 Controller 中我需要类似的东西:
circle.MarginLeft = 120;
最佳答案
您可以使用您的模型或 ViewBag
。
在 Controller 中将您的数据传递到对象中,例如 circle.MarginLeft = 12
或使用 ViewBag['marginLeft'] = 12
并在您的.cshtml
文件集中
<div class="circle" style="margin-left:@ViewBag.marginLeft"></div>
或
<div class="circle" style="margin-left:@Model.marginLeft"></div>
关于c# - 从 Controller 动态更改 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56404291/