1

现在我正在使用MVC webgrid。我需要根据需求设置列宽。MVC webgrid列宽?

网:

@{ 
    var grid = new WebGrid(source: Model.TenantList, rowsPerPage: 11, canPage: true, canSort: false); 
     @grid.Table(
     headerStyle: "headerStyle", 
     tableStyle: "table table-responsive fixed-column fixed-column table-striped table-hover a-grid", 
     alternatingRowStyle: "alternateStyle", 
     htmlAttributes: new { id = "tenantgrid" }, 
     columns: grid.Columns(
     grid.Column("Action", style: "labelcolumn cchk",format:@<text><input class="checkbox cchk" id="assignChkBx" name="assignChkBx" value="@item.Person_Code" type="checkbox" onClick="assignChkBx()" /></text>), 
     grid.Column("TitleName"), 
     grid.Column("FullName",style: "name-width"), 
     grid.Column("Employee_Number"), 
     grid.Column("Fathername"), 
     grid.Column("Address"), 
     grid.Column("EMAILID") 
     ) 
    ) 
    } 

的CSS:

.name-width { 
     width:500px; 
    } 

问题是类被称为像这样

<td class="name-width">AMEER ABOOBACKER</td> 

但它不是我的应用网格。我找不到这个错误。朋友给我解决方案........ 感谢提前。

回答

0

您可以为您提到的每一列指定一个类。 你的桌子有你的风格固定列和最有可能的是覆盖你的自定义CSS。您可以删除该类(并使用下面的代码)或者您可以尝试将!important添加到您的css属性中。 下面应该按预期工作。

@grid.GetHtml(tableStyle: "table table-hover", 
         columns: 
     grid.Columns 
     (
       grid.Column("Property1", "Property1", style: "Large"), 
       grid.Column("Property2", "Property2", style: "Small") 
       grid.Column("Action", format: @<text> 
        @Html.ActionLink("Edit", "Edit", new { id = item.Id}) 
        | @Html.ActionLink("Delete", "Delete", new { id = item.Id }) 
       </text>, style: "action", canSort: false))) 

<style type="text/css"> 
.Large{ 
    width: 20%; 
} 

.Small{ 
    width: 5%; 
}