Skip to content

Instantly share code, notes, and snippets.

@umair-me
Last active August 18, 2016 13:07
Show Gist options
  • Save umair-me/091f5b3771885f42cac5990cc0d6a05f to your computer and use it in GitHub Desktop.
Save umair-me/091f5b3771885f42cac5990cc0d6a05f to your computer and use it in GitHub Desktop.
Action Name strings to Expression Func - get the method name by using a better way instead of hard-coding strings names for actions
Expression<Func<ProductController, ActionResult>> add = (p => p.Add(null));
Expression<Func<ProductController, ActionResult>> edit = (p => p.Edit(null));
var action = (Id == 0) ? add : edit;
string actionMethodName = ((MethodCallExpression)action.Body).Method.Name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment