Nested BeginCollectionItem

前端 未结 3 1108
滥情空心
滥情空心 2020-12-16 16:39

I\'m using Steve Sanderson\'s BeginCollectionItem approach to add dynamic content. Everything works fine when I\'m doing it on the first level. However, when try to implemen

3条回答
  •  一整个雨季
    2020-12-16 17:05

    To get the prefix with an Html.BeginCollectionItem, you can access ViewData.TemplateInfo.HtmlFieldPrefix (I'm using the nuget package). You're on the right track with tt.transfers, but you need the specific prefix instead.

    Instead of just

    Html.BeginCollectionItem("tt.transfers")
    

    you'll need the prefix of the current payment_method as well.

    @{
        var paymentMethodPrefix = ViewData.TemplateInfo.HtmlFieldPrefix;
    }
    @using (Html.BeginCollectionItem(paymentMethodPrefix + ".tt.transfers"))
    

    and a quick test looks like you can also just:

    @using (Html.BeginCollectionItem(ViewData.TemplateInfo.HtmlFieldPrefix + ".tt.transfers"))
    

提交回复
热议问题