ASP.NET MVC: shortcut for Response.Write and String.Format
Posted
by pcampbell
on Stack Overflow
See other posts from Stack Overflow
or by pcampbell
Published on 2010-05-04T15:35:46Z
Indexed on
2010/05/04
15:38 UTC
Read the original article
Hit count: 1350
asp.net-mvc
|.net-4.0
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?
© Stack Overflow or respective owner