开发者

MVC Razor View Engine, add logic between quotemarks

开发者 https://www.devze.com 2023-02-16 15:52 出处:网络
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.

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

精彩评论

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