我想创建一个自定义网格,它将具有三列,行可以是任何数量,具体取决于数据。但我的问题是数据以 json 格式提供。我已经多次创建了类似网格的结构,但这是使用模型和集合,例如:
首先为列创建 div
@{
if (Model.MessageList.Count > 0)
{
<div class="GridView_Div">
<div class="GridHeader_Div">
<div class="GridHeaderColoums_Div">Message</div>
<div class="GridHeaderColoums_Div">Sent Date</div>
<div class="GridHeaderColoums_Div">Receive Date</div>
<div class="GridHeaderColoums_Div">Actions</div>
</div>
<div class="GridData_Div">
@{
for (int i = 0; i < Model.MessageList.Count; i++)
{
string resultMessage = string.Empty;
string newMessage = string.Empty;
string result1 = Model.MessageList.ElementAt(i).Message;
int length = result1.Length;
if (length > 5)
{
resultMessage = result1.Substring(0, 5);
newMessage = resultMessage + "......";
}
else
{
resultMessage = result1.Substring(0);
newMessage = resultMessage + "......";
}
<div class="Grid_Row">
<div class="GridData_Coloums">
<a href="#" onclick="ShowMessageDetail('@Model.MessageList.ElementAt(i).pkMessageId')" id="@Model.MessageList.ElementAt(i).pkMessageId">@newMessage</a>
</div>
<div class="GridData_Coloums">@Model.MessageList.ElementAt(i).Sent_Date</div>
<div class="GridData_Coloums"> @Model.MessageList.ElementAt(i).Receive_Date</div>
<div class="GridData_Coloums">
<input type="button" value="Delete" id="@Model.MessageList.ElementAt(i).pkMessageId"/>
</div>
</div>
}
}
</div>
</div>
}
else
{
<div style="width: 50%; float: left; margin-left: 10%;">No Message Found</div>
}
}
但是如何在 Json 数据中创建类似网格的结构呢?
请帮我处理这个案子。非常感谢