ASP.NET MVC: shortcut for Response.Write and String.Format
- by pcampbell
I've found a pattern in my Views like this:
<% if (someCondition)
{
Response.Write(string.Format("Hello {0}, Visitor {1} on {2}.", userName, someCounter, someDate)); }
else
{
Response.Write(string.Format("Foo is {0}.", bar));
}
%>
The question here is around DRY and Response.Write(string.Format()). Are there better, or more concise ways to . Consider that HTML encoding would be a nice feature to include, perhaps as a boolean to a method call of some kind (extension method on Html?.
Is there an obvious extension method that I'm missing?
Do you have an extension method that you rely on to achieve this functionality?