I've read some posts with some self implementations of this but I think now there should be some method in the ASP.NET MVC that should have this functionality.
I suppose there is some kind of method that can do what string.Format does:
string.Format("example {0}", 1);
but instead of using {0} can work with variables names just like the MVC routes. for example:
string.Format("example {id}", 1);
Is there such public method in ASP.NET MVC?
[Edit: Any idea how for example are action links rendered out of routes?]
As of C# language version 6.0 (VS2015 onwards) you can do this with Interpolated Strings (it's a compiler trick, so it doesn't matter which version of the .NET Framework you target).
The code then looks something like this
string txt = $"{person.ForeName} is not at home {person.Something}";
I think it makes the code more readable and less error prone, but it's not ideal if you want to put the strings into resource files for translation.
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