Retrieving Property name from lambda expression

前端 未结 21 1720
迷失自我
迷失自我 2020-11-21 11:12

Is there a better way to get the Property name when passed in via a lambda expression? Here is what i currently have.

eg.

GetSortingInfo         


        
21条回答
  •  情话喂你
    2020-11-21 11:47

    This is another answer:

    public static string GetPropertyName(this HtmlHelper htmlHelper,
                                                                          Expression> expression)
        {
            var metaData = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData);
    
            return metaData.PropertyName;
        }
    

提交回复
热议问题