How do I build my html inside the razor foreach? I get "Cannot resolve tbody" inside the foreach.
My code:
function loadNyhedsbrevTable() {
var tbody = "";
$('#NyhedsbrevTable tbody').empty();
@foreach (string n in ViewBag.NyhedsbrevListe)
{
tbody = '<tr><td>' + n + '</td></tr>';
}
$('#NyhedsbrevTable tbody').append(tbody);
}
Do I need something like this?
<not razor> tbody = '<tr><td>' + @n + <not razor>'</td></tr>'
;
Is this what you are looking for? I hope this help
@foreach (string n in ViewBag.NyhedsbrevListe)
{
@:tbody = '<tr><td>' + n + '</td></tr>';
}
Source: http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With