本文介绍了HTML.Display()不显示任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚开始使用MVC和有以下code:
I'm just starting out with mvc and have the following code:
@model AzureDemo.Models.User
@{
ViewBag.Title = "Interests";
}
<h2>Interests</h2>
<p>
@Html.ActionLink("Logout", "Logout")
</p>
<table>
<tr>
<th>
Interests
</th>
</tr>
@foreach (var interest in Model.Interests) {
<tr>
<td>
@Html.Display(interest)
</td>
//Tried like this
<td>
@Html.Display("id", interest.ToString())
</td>
</tr>
}
</table>
在用户兴趣属性只是一个字符串列表。我想显示用户在表中的每个兴趣。我也试图把一个字符串,如测试在Html.Display,或使用的ToString(),但仍然一无所获。
The Interests property in User is simply a list of strings. I'm trying to display each interest in a table for a user. I also tried putting a string like "test" in Html.Display, or tried using ToString() but still nothing.
推荐答案
您可以直接使用模型项目类似这样
You can use directly model item like this
@foreach (var interest in Model.Interests) {
<tr>
<td>
@interest
</td>
// or this
<td>
@interest.ToString()
</td>
</tr>
}
或者如果你显示HTML codeS在你看来那么这是更安全的。
or if you show html codes in your view then this is more safety
@foreach (var interest in Model.Interests) {
<tr>
<td>
@Html.Raw(interest)
</td>
</tr>
}
给我这个机会也感谢;)
Also thanks for this chance ;)
这篇关于HTML.Display()不显示任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!