gpt4 book ai didi

c# - 从 Controller 动态更改 css

转载 作者:行者123 更新时间:2023-11-30 17:26:31 24 4
gpt4 key购买 nike

我是 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com