[英]How do I make Html.DisplayFor work in this case?
I have this class: 我有这个课:
public class UserMessage
{
public int UserMessageId { get; set; }
[Required]
[StringLength(50)]
public string Name { get; set; }
[Required]
[EmailAddress]
public string Email { get; set; }
[Required]
public string MessageType { get; set; }
[Required]
[StringLength(300)]
[DataType(DataType.MultilineText)]
public string Message { get; set; }
}
And in the view I have: 在我看来:
@model IEnumerable<Kekanto.Models.UserMessage>
@foreach (var message in Model)
{
@Html.DisplayFor(message)
}
I want to display the data in the view.... I donw know how to do in this case... I know I can make @Html.DisplayFor(message=>message.Message) and write Display for all the fields... But I was wondering if I could make with a single comand 我想在视图中显示数据...。在这种情况下,我不知道该怎么做...我知道我可以使@ Html.DisplayFor(message => message.Message)并为所有字段编写Display。 ..但是我想知道是否可以用一个命令
instead of using DisplayFor
you can just use Display
而不是使用
DisplayFor
您可以只使用Display
@foreach (var message in Model)
{
Html.Display(message)
}
But if you are just displaying data i would use something other than display maybe Html.Raw() 但是,如果您只是显示数据,我可能会使用其他而不是display的Html.Raw()
@{
string str = "";
foreach (var message in Model)
{
str = str + message ;
}
}
@Html.Raw(str)
.net怎么样?
@string.Join(", ", Model.Select(T => T.Message))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.