我有一个要渲染到网页的数据表。我想在每一行上显示一个复选框。但是,当我尝试显示它时,它会显示 html。有没有办法解决?
类定义:
public int analysisId { get; set; }
public string heatName { get; set; }
public DateTime analysisTime { get; set; }
public string sampleType { get; set; }
public string grade { get; set; }
public string productId { get; set; }
public string element { get; set; }
public float value { get; set; }
我的模型中的代码如下:
DataTable GridData = new DataTable();
GridData.Columns.Add("CheckBoxes");
GridData.Columns.Add("Analysis ID");
GridData.Columns.Add("Analysis Time");
GridData.Columns.Add("Sample Type");
GridData.Columns.Add("Product ID");
foreach (var item in elementheaders)
{
GridData.Columns.Add(item.Trim());
}
int gridend = GridData.Columns.Count;
int gridrow = 0;//x
int listrow = 0;//z
int checknum = 0;
foreach (int analysis in ChemList.Select(d => d.analysisId).Distinct())
{
DataRow dr = GridData.NewRow();
GridData.Rows.Add(dr);
GridData.Rows[gridrow][0] = System.Web.HttpUtility.HtmlDecode("<input type='checkbox' id="+checknum+">");
GridData.Rows[gridrow][1] = ChemList[listrow].analysisId;
GridData.Rows[gridrow][2] = ChemList[listrow].analysisTime;
GridData.Rows[gridrow][3] = ChemList[listrow].sampleType;
GridData.Rows[gridrow][4] = ChemList[listrow].productId;
}
在我看来:
<div id="grid">
<table id="example" class ="gridTable">
<thead class="gridHead">
<tr>
@Html.DisplayFor(x => x.Columns)
</tr>
</thead>
<tbody>
@Html.DisplayFor(x => x.Rows)
</tbody>
</table>
</div>
单元格的显示模板:
@model TheManhattanProject.Models.CellValueViewModel
<td>
@Html.DisplayFor(x => x.Value)
</td>
行的显示模板:
@model TheManhattanProject.Models.RowViewModel
<tr>
@Html.DisplayFor(x => x.Values)
</tr>
列的显示模板:
@model TheManhattanProject.Models.ColumnViewModel
<th>
@Html.DisplayFor(x => x.Name)
</th>
我有两个用于渲染的视图模型。每个单元格和行一个。该行由一个单元格值列表组成。