Created
April 24, 2015 13:58
-
-
Save Warrenn/0872e67350bf64c0fb88 to your computer and use it in GitHub Desktop.
ViewData Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ViewDataExtension | |
{ | |
public static void DisplayContext<T>(this ViewDataDictionary viewData, T instance, string key = null) | |
{ | |
var keyValue = (string.IsNullOrEmpty(key)) ? typeof(T).FullName : typeof(T).FullName + "." + key; | |
viewData[keyValue] = instance; | |
} | |
public static T DisplayContext<T>(this ViewDataDictionary viewData, string key = null) | |
{ | |
var keyValue = (string.IsNullOrEmpty(key)) ? typeof(T).FullName : typeof(T).FullName + "." + key; | |
var returnValue = viewData.Eval(keyValue) ?? default(T); | |
return (T)returnValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment