MVC 6标签助手和foreach [英] MVC 6 Tag Helpers and foreach

查看:47
本文介绍了MVC 6标签助手和foreach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将如何赋予标签标签助手的asp-for属性以显示集合中的项目.下面的代码生成编译错误.

What would I give to asp-for property of a label tag helper in order to display items from a collection. The code below generates a compilation error.

@foreach (var item in Model)
{
    <label asp-for="item.BookingCode"></label>
}

推荐答案

@字符转义默认的模型lambda代码.因此,您可以输入:

The @ character escapes the default model lambda code. Therefore you can type:

@foreach (var item in Model)
{
    <label asp-for="@item.BookingCode"></label>
}

这篇关于MVC 6标签助手和foreach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆