O.K. I think that's an easy one!
I have a ViewMasterPage with some links on it (Home/About/Login/ etc). What I want to achieve is simply have the link disabled when it's referral url is already opened (i.e. if the current url is /Register then the Register link should be disabled .. easy hah!?)
As I don't like to write a lot of in-line coding inside of my views, I end up extending HtmlHelper with some extension methods (just to keep the code in .cs files) and in my views I call these methods, here's my register method as an example:
public static string Register (this HtmlHelper html)
{
TagBuilder builder ;
if (HttpContext.Current.Request.Url.AbsoluteUri.ToUpperInvariant().Contains(MainLinks.Register.ToUpperInvariant()))
return MainLinks.Register; // will return the string "Register"
builder = new TagBuilder("a");
builder.InnerHtml = MainLinks.Register;
builder.AddCssClass("register");
builder.Attributes.Add("href", "/register/");
return builder.ToString();
}
Though this works, it still has two problems:
The hard coded string values of the urls (specially for the home link as I compare the AbslouteUri with "http://www.mysite.com/")
My programming instinct doesn't like it, I feel it should be much simpler than that.
Any ideas!
Ps: No javascipt allowed! It's a javascript-free version of the application.