I have baseUrl = "http://localhost:10232";
I'm using it in my view like the following:
<a href='@mynamespace.Controllers.MyVars.baseUrl/Tickets/Create'>Create New</a>
It gives me fine output i.e
<a href='http://localhost:10232/Tickets/Create'>Create New</a>
But if I add /
at end of my url like http://localhost:10232/
Then is there a way to produce same result like above? I tried it following way
<a href='@mynamespace.Controllers.MyVars.baseUrl+Tickets/Create'>Create New</a>
but concatenation does not work in html, so how can i achieve it (concat a c# variable with html string)
As you know, the best way to concatenate two strings in C programming is by using the strcat() function.
In C, "strings" are just plain char arrays. Therefore, you can't directly concatenate them with other "strings".
Wrap it in parenthesis and the static part in quotes:
<a href='@(mynamespace.Controllers.MyVars.baseUrl+"Tickets/Create")'>Create New</a>
^ ^ ^^
This tells Razor anything inside the @()
is one statement, allowing you to put C# in to concatenate the string.
Or if your last part is always static, you can leave out the quotes and move the text outside the parenthesis:
<a href='@(mynamespace.Controllers.MyVars.baseUrl)Tickets/Create'>Create New</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With