Is there an equivalent method to MvcHtmlString in .Net 3.5 and lower? I have googled and have not found an answer. I created a helper for MVC 3/.NET 4 that uses MvcHtmlString. However it only runs on .NET 4. I want to code a version of the helper so it can run on Mvc 2/.net 3.5 so i can use the helper on another project which uses this runtime. Would i just use stringbuilder and return Stringbuilder.ToString?
Share
MvcHtmlStringdoes work on both .NET 3.5 and .NET 4 – it has a staticCreate()method that should be used to create a new instance.The reason for the static factory method is so that runtime inspection can be used to determine if the environment is .NET 4 or .NET 3.5; if the environment is .NET 4, then a new type is declared at runtime that derives from MvcHtmlString and implements
IHtmlStringso that the new<%: %>response write with encoding syntax works.The source code for this looks like (taken from the MVC 2 Source code)