There must me a more elegant way to build a URL with parameters in .NET then for example
Response.Write("<a href=HeadOfMarketView.aspx"+Session["HOM"] != null ? Session["HOM"]+">Head of Market</a> / ")
I mean the co开发者_开发技巧ncatenation of strings is a litte bit old school, no?
Maybe this is better:
Response.Write(string.Format("<a href=HeadOfMarketView.aspx?param={0}>Head of Market</a>", Session["HOM"] as string ?? "" ));
EDIT: Response to the comment (C# 3.0, .NET 3.5):
Response.Write(string.Format("<a href=HeadOfMarketView.aspx{0}>Head of Market</a>", Session["HOM"].ToUrlParamString()));
public static class UrlHelper
{
public static string ToUrlParamString(this object val)
{
return val != null ? "?" + val : string.Empty;
}
}
精彩评论