ASP.Net MVC 3 Razor Concatenate String
DisplayFor
needs a property to map to, so a concatenation is impossible. You might expose a read-only property FullName on your model, which then returns the concatenation:
public string FullName
{
get
{
return User.FirstName + " " + User.LastName;
}
}
and then use that in your DisplayFor
.
@Html.DisplayFor(modelItem => modelItem.FullName);
@Html.DisplayFor(modelItem => item.FirstName) @Html.DisplayFor(modelItem => item.LastName)
You can do this:
@foreach (var item in Model.FormNotes) {
var conc = item.User.FirstName + item.User.LastName;
<tr>
<td>
@Html.Display(conc)
</td>
</tr>
}
Or it would be better solution to have property FullName in model