0

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.