Trying to use a loop to build a series of table rows in Razor:
MvcHtmlString filesList = MvcHtmlString.Create("");
foreach (var file in orderRow.Files)
{
fileList = fileList + "<tr><td colspan='2'><a href='http://@file.Location/file.FileName' target='_blank'>@file.Description </a></td></tr>";
}
@filesList
}
How to concatenate several MvcHtmlString instances leads me to think i’m on the right track with the above code but i’m working against Razor an am experiencing different mileage.
thx
You’re over-complicating the problem. You don’t need to build a string at all for your situation, since you’re just outputting the string directly after the loop. You can do this:
http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx