Hello, I am trying to pass this string from back-end C# to front end, and want to render it as HTML, when passing this string to the front-end, it doesn't look proper, here is my current C# code.
var str="<span href='/ShowQuote/" +QID+ "?NewTab=True' style='margin: 10px; text-decoration:none' class='ShowQuoteClick'>Fetched one quote for " + MainCompanyName + " with Id-" + Id + "</span>";
in the above code QID
, MainCompanyName
& Id
is C# variables, so how can I insert variable values in the middle of a string properly, using C#?
Here are the ways to insert C# variable in between a string:
var str="<span href='/ShowQuote/{0}?NewTab=True' style='margin: 10px; text-decoration:none' class='ShowQuoteClick'>Fetched one quote for {1} with Id-{2}</span>";
var newStr=string.Format(str, QID,MainCompanyName,Id);?
var QID= "1";
var MainCompanyName = "Test";
var Id="11";
var str = $"<span href='/ShowQuote/{QID}?NewTab=True' style='margin: 10px; text-decoration:none' class='ShowQuoteClick'>Fetched one quote for {MainCompanyName} with Id-{Id}</span>";
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly