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

查看:10
本文介绍了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天全站免登陆