我在ASP.Net MVC 4項目中定義一個定製的幫手如下無法轉換lambda表達式到類型「INT」
public static class CustomHelpers
{
public static string UserNameForID(int UserIDValue)
{
// do database operation and return record for UserIDValue
return "ABC";
}
}
在我看來,我的代碼
@model ABC.DataAccess.Product
@CustomHelpers.UserNameForID((model=>model.LAST_UPDATE_BY))
以上代碼給出了這樣的錯誤:
"Cannot convert lambda expressions to type 'int' becasue it is not a delegate type.
但是如果我測試上述代碼
@CustomHelpers.UserNameForID(1)
應用程序返回按預期的方式串ABC
。
如何解決此錯誤?我想傳遞存儲在模型的LAST_UPDATE_BY
中的值。
爲什麼使用雙括號 –