Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

prefix controls in a partial view

$
0
0

Hi 

I would like to add a prefix to controls in a partial view so that they bind correctly to the model on submitting a form however the way to do this by passing a viewdatadictionary with templateinfo as a parameter in the @html.partial method does not appear work with .net core.

@Html.Partial("_AddressView", Model.Donor.Address, new ViewDataDictionary
{
TemplateInfo = new TemplateInfo{ HtmlFieldPrefix = nameof(Model.Donor.Address) }
})


update: I finally got a solution to work in the meantime though not sure it's the best or even recommended but thought I'd share. You have to remember to reset the prefix after this otherwise all controls after the partial view will also have this prefix.

@{ViewData.TemplateInfo.HtmlFieldPrefix = "Donor.Address"; }

@Html.Partial("_AddressView", Model.Donor.Address)

Is this no longer available in .net core. Any help would be much appreciated.

Thanks


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>