MVC 3 - HTML Helper
I was going to use declarative HTML helpers, but then found out that they have not been implemented in a release of MVC 3. I'm trying to get old HTML helpers to work with the follo
Solution 1:
David Neale is right, but in ASP.NET MVC 3 you should actually return an instance of HtmlString
, not MvcHtmlString
(both will work, though):
private static HtmlString GenerateSingleOptionHTML(Question q)
{
String ret = "";
for(int i = 0; i < 3; i++)
{
ret += String.Format("<li><input type=\"radio\" id=\"Q" + i
+"\" value=\"" + i + "\" name=\"Q" + i +"\" />" + q.Body + "</li>");
}
return new HtmlString(ret);
}
Solution 2:
You need to return an instance of MvcHtmlString. Your output string is getting encoded.
The MvcHtmlString
object will be treated as already encoded during rendering (I assume you're using the <%: %>
syntax instead of <%= %>
to inject the HTML into the page).
return MvcHtmlString.Create(ret);
Post a Comment for "MVC 3 - HTML Helper"