我想寫一個EditorTemplate到一般應用依賴於一個輔助提供使從ViewBag模型和附加數據的邏輯CSS類:使用lambda從剃刀局部視圖指定屬性的Helper類
@using LSC.DCMP.Web.UI.Helpers
@model String
@ValidationFieldHelper.GetCSSClass(m => Model, @ViewBag.Step)
此相匹配,目前未實現一個輔助類,但具有以下特徵:
public static class ValidationFieldHelper
{
public static object GetCSSClass(Func<object, string> func, object step)
{
throw new NotImplementedException();
}
}
當我嘗試運行應用程序,它無法編譯,出現以下錯誤:
"Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type".
我讀過lambda語法不完全支持使用Razor模板,所以我不確定如何實現此功能。