Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use html and escape razor inside a razor foreach?

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>';

like image 815
radbyx Avatar asked Feb 14 '23 18:02

radbyx


1 Answers

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

like image 138
nico008 Avatar answered Mar 03 '23 07:03

nico008