开发者

MVC Razor View Engine, add logic between quotemarks

I'm really new at using Razor with MVC, and so far I really like it.

One little thing I want to do is write a variables value to an attribute in HTML. For example, if I had the following:

开发者_StackOverflow中文版
    <table style="width: 100%">
        <tr>
            <th>
                ID
            </th>
            <th>
                Name
            </th>
            <th>
                Value
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr id="ID@item.id">
                <td>
                    @item.id
                </td>
                <td>
                    @item.name
                </td>
                <td>
                    @item.value
                </td>
                <td>
            </tr>
        }
    </table>

I would want all the tags to have an ID equal to "ID[insert item's id]", but instead I get an ID equal to "ID@item.id".

How do I write a variable's name between HTML quote marks?

Thanks!


This pattern is recognized as an email address. Do the following to work around this behavior:

<tr id="ID@(item.id)">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜