我有一个类似的模型:
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)
如果有人能给我一些如何解决这个问题的线索我真的很感激!
请考虑以下代码:
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)