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
instead of using DisplayFor
you can just use 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()
@{
string str = "";
foreach (var message in Model)
{
str = str + message ;
}
}
@Html.Raw(str)
.net怎么样?
@string.Join(", ", Model.Select(T => T.Message))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.