简体   繁体   中英

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?

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. You can then use the partial tag helper like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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