How to change the HtmlFieldPrefix index?
I get Children[0]from EditorFor (), and I want to make it Children[@Model.Id]or Children[2].Children[4]from EditorFor (), and I want to do itChildren[@"ParentModel".Id].Children[@Model.Id]
Children[0]
Children[@Model.Id]
Children[2].Children[4]
Children[@"ParentModel".Id].Children[@Model.Id]
I will not know the actual prefix until executed. Preferably, is there a built-in way to change it?Or just messing around with a string? I'm still new to C # string functions.
Try placing the following inside an editor template:
@model SomeViewModel @{ ViewData.TemplateInfo.HtmlFieldPrefix = Regex.Replace( ViewData.TemplateInfo.HtmlFieldPrefix, @"\[[0-9]+\]$", m => string.Format("[{0}]", Model.Id) ); }