相关疑难解决方法(0)

Razor View Engine:表达式树可能不包含动态操作

我有一个类似的模型:

public class SampleModel
{
     public Product Product { get; set; } 
}
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,我尝试打印出异常

@Html.TextBoxFor(p => p.Product.Name)
Run Code Online (Sandbox Code Playgroud)

这是错误:

Exception: An expression tree may not contain a dynamic operation
Run Code Online (Sandbox Code Playgroud)

如果有人能给我一些如何解决这个问题的线索我真的很感激!

asp.net-mvc .net-4.0 razor

164
推荐指数
5
解决办法
9万
查看次数

为什么在尝试使用动态参数调用扩展方法时出现错误CS1973

请考虑以下代码:

internal static class Program
{
    public static string ExtensionMethod(this string format, dynamic args)
    {
        return format + args.ToString();
    }

    private static void Main()
    {
        string test = "hello ";
        dynamic d = new { World = "world" };

        // Error CS1973  'string' has no applicable method named 'ExtensionMethod'
        //                but appears to have an extension method by that name. 
        //               Extension methods cannot be dynamically dispatched. 
        //               Consider casting the dynamic arguments or calling
        //               the extension method without …
Run Code Online (Sandbox Code Playgroud)

c# extension-methods dynamic dispatch

3
推荐指数
1
解决办法
473
查看次数