Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将lambda表达式转换为类型';int';_C#_Asp.net_Asp.net Mvc_Html Helper - Fatal编程技术网

C# 无法将lambda表达式转换为类型';int';

C# 无法将lambda表达式转换为类型';int';,c#,asp.net,asp.net-mvc,html-helper,C#,Asp.net,Asp.net Mvc,Html Helper,我在ASP.NETMVC4项目中定义了一个自定义助手,如下所示 public static class CustomHelpers { public static string UserNameForID(int UserIDValue) { // do database operation and return record for UserIDValue return "ABC"; } } 在我看来,我有代码 @model ABC.D

我在ASP.NETMVC4项目中定义了一个自定义助手,如下所示

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))
上述代码给出了此错误:

“无法将lambda表达式转换为“int”类型,因为它不是委托类型

但是如果我测试上面的代码

@CustomHelpers.UserNameForID(1)
应用程序按预期返回字符串
ABC

如何解决此错误?我想通过模型的传递存储在上次更新中的值。

您试图将表达式强制转换为该表达式的结果。只需使用:

@model ABC.DataAccess.Product
@CustomHelpers.UserNameForID(Model.LAST_UPDATE_BY)

model=>model.LAST\u UPDATE\u BY
根据类型
Expression
生成一个参数(有关示例,请参见
Html.EditorFor()

CustomHelpers方法需要int类型的参数,因此必须像以下那样调用它:

@CustomHelpers.UserNameForID(Model.LAST_UPDATE_BY)

你为什么用双括号?