简体   繁体   English

如何在ASP.NET Core剃须刀中对绑定标签助手进行建模

[英]How to model bind a tag helper in asp.net core razor

Is there a way for me to replace the functionality of Html.EditorFor(m => m.ListOfItems) in Asp.net Core Razor pages? 有没有办法替换Asp.net Core Razor页面中Html.EditorFor(m => m.ListOfItems)的功能?

I was looking at tag helpers which remind me of components, however I haven't been able to get these to model bind correctly (in a loop). 我当时在看标记帮助器,它们使我想起了组件,但是我无法使它们正确地建模(循环)。 Am I basically forced to use editor templates for now? 我现在是否基本上被迫使用编辑器模板?

According to the documentation here , this is exactly the method show. 根据此处的文档,这正是显示的方法。 This means there is no direct tag helper solution anytime soon. 这意味着不久将没有直接的标签帮助器解决方案。

However, instead of doing this with editor templates, you can always create a partial view that uses tag helpers for your Item class. 但是,除了使用编辑器模板执行此操作外,您始终可以创建对Item类使用标签帮助程序的局部视图。 You can then use the partial tag helper like this: 然后,您可以使用部分标签帮助程序,如下所示:

@foreach (var item in Model.ListOfItems)
{
    <partial name="MyItem" model="item" />
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM