c# - 从 Controller 动态更改 css

标签 c# asp.net-mvc

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

相关文章:

asp.net-mvc - 托管我的 ASP.NET MVC 3 应用程序

c# - Expression.Call 类型 System.Collections.Generic.ICollection 上不存在方法 'Select'

c# - C# 代码的构建问题 - CS0012 - IsLongModifier

c# - 如何连接一行中的所有列值,然后将 DataTable 中的所有行连接成一个字符串?

c# - 当使用 ajax 发送到 Controller 时,日期正在改变

c# - .NETCoreApp是哪个MVC版本,版本=v1.0?

c# - 无法选择数据绑定(bind)的 DataGridView 中的复选框

c# - 在 Monotouch 中增加 ThreadPool 线程数?

asp.net-mvc - 部分验证 ASP.NET MVC

jquery - Facebook 评论插件