css - 在 MVC3 中设置 webgerid 列宽

标签 css asp.net-mvc asp.net-mvc-3

我定义了一个 WebGrid 控件,我想设置列宽,因此我按以下方式设置列宽

Grid.Column("Details", canSort: false, format: (item) => Html.ActionLink("Details", "Details", new { id = item.CompetitiveExam.CompetitiveExamId }),style:"details")

我的 CSS 类就像...

.details{ width:100px; }

上面的代码可以正常工作,但我不想使用单独的 css 类。

我也在尝试使用嵌入式 css 来跟踪代码,但它不起作用......

Grid.Column("Details", canSort: false, format: (item) => Html.ActionLink("Details", "Details", new { id = item.CompetitiveExam.CompetitiveExamId }),style:"width:100px")

请任何人帮助我....................

最佳答案

参数名称“style”是一个不幸的选择。它仅用于类名,不用于内联样式声明。

选项 1。

如果您真的想在不使用 css 的情况下更改您的列宽,还有另一个 Html.ActionLink 重写,它将 htmlAttributes 作为第四个参数。它会在每一行上呈现这些属性,因此它不是最有效的,但它可以工作。

new { style = "display:inline-block; width:100px;" } 

这是完整的行

Grid.Column("Details", 
            canSort: false, 
            format: (item) => Html.ActionLink("Details", 
                        "Details", 
                        new { id = item.CompetitiveExam.CompetitiveExamId }, 
                        new { style = "display:inline-block; width:100px;" }
                    )
           )


选项 2。

对于您希望任何列类型都包含格式的更一般情况,只需包含具有所需格式的包装器 html。不过,这会使您的文档比需要的更大:

format: ((item) => new MvcHtmlString("<div style='width:100px;'>" + 
                   "your content here" + 
                   "</div>"))

关于css - 在 MVC3 中设置 webgerid 列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9633795/

相关文章:

html - VIM 中的 HTML 和 CSS 文件没有自动完成 (YouCompleteMe)

jquery - 如何通过 json 结果绑定(bind)我的下拉列表?

asp.net-mvc - 从 ActionFilter 返回 View

asp.net-mvc - 以编程方式更改验证范围 (MVC3 ASP.NET)

asp.net-mvc - 在 ASP.NET MVC 3 的类库中使用 MEF

mysql - 使用 code first 和 mysql 插入中文数据时出现问题

html - 全尺寸窗口内的灵活和固定 div 行

html - 将 CSS 合并到 html 中

html - CSS 在数据单元格上方显示表格行标题

c# - 在本地调试 Azure 函数提供了一个有趣的 AppDomain.CurrentDomain.BaseDirectory 路径