Reputation: 1326
I have the following Blazor code where data values are input from a JSON file.
<p>@product.Name</p>
<p>@((MarkupString)product.Description)</p>
What I would like to do is embed @product.Name into the Description text in the JSON file so it is rendered as part of the description. I am looking for something simple like this:
"Description": "This a detailed description of the <dummytag>@product.Name</dummytag> product or service".
I've tried various combinations but have not been able to render gen3Product.Name. Can anyone tell me how to do this, please. I know this can lead to bad security outcomes.
Upvotes: 0
Views: 206
Reputation: 273179
In Blazor, @product.Name
has to be compile prior to deployment. So embedding this in your data won't work.
You can however use old style string formatting:
"Description": "This a detailed description of the <dummytag>{0}</dummytag> product or service"
and then
<p>@((MarkupString) string.Format(product.Description, product.Name)</p>
but this is obviously less flexible.
Upvotes: 2