I am trying to create an id for an input by doing the following
id="@ViewData.ModelMetadata.ContainerType.Name + "_" + @ViewData.TemplateInfo.GetFullHtmlFieldId("FromDate")"
but it is coming through with id=”propertyName +”. How can I concatenate the two together with an underscore in the middle in a razor view?
You can use the
@(expression)syntax to express an explicit code expression.You need to be explicit here because the space after
@ViewData.ModelMetadata.ContainerType.Nameis not a valid character for a C# identifier so the evalutation stops there.The algorithm used by Razor for processing implicit code expression is the following:
(Taken from ScottGu’s Blog)