Get a Request.Params value by taking advantage of the DynamicObject to make the code look more static
public static class Helper
{
public static dynamic Request
{
get { return new Request(); }
}
}
public class Request : DynamicObject
{
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
var name = binder.Name.ToLower();
result = HttpContext.Current.Request.Params[name];
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
throw new NotSupportedException();
}
}
Can be used like this for example in Razor:
@Helper.Request.Search
It will display the value of the QueryString or Input field.
Fork
2 Feedback
Really like it. It gives you much cleaner code since you don´t have to use strings. - @vimpyboy Friday 23, 2010 3:18 PM
Nice, Razor looks nice the little I have seen. Clean and nice code too :) - @johannormen Friday 23, 2010 4:47 PMYou must log in before you can give any feedback
You must log in before you can post a comment


870
0



Mark 'asp.net' tag as 'like'
Mark 'asp.net' tag as 'ignore'