Razor View Engine : An expression tree may not contain a dynamic operation

后端 未结 7 1833
不思量自难忘°
不思量自难忘° 2020-11-28 08:50

I have a model similar to this:

public class SampleModel
{
     public Product Product { get; set; } 
}

And in my controller I get an excep

相关标签:
7条回答
  • 2020-11-28 09:23

    In this link explain about @model, see a excerpt:

    @model (lowercase "m") is a reserved keyword in Razor views to declare the model type at the top of your view. You have put the namespace too, e.g.: @model MyNamespace.Models.MyModel

    Later in the file, you can reference the attribute you want with @Model.Attribute (uppercase "M").

    0 讨论(0)
  • 2020-11-28 09:33

    A common error that is the cause of this is when you add

    @Model SampleModel
    

    at the top of the page instead of

    @model SampleModel
    
    0 讨论(0)
  • 2020-11-28 09:35

    This error happened to me because I had @@model instead of @model... copy & paste error in my case. Changing to @model fixed it for me.

    0 讨论(0)
  • 2020-11-28 09:38

    It seems to me that you have an untyped view. By default, Razor views in MVC3 RC are typed as dynamic. However, lambdas do not support dynamic members. You have to strongly type your model. At the top of your view file add

    @model SampleModel
    
    0 讨论(0)
  • 2020-11-28 09:39

    On vb.net you must write @ModelType.

    0 讨论(0)
  • 2020-11-28 09:45

    Seems like your view is typed dynamic. Set the right type on the view and you'll see the error go away.

    0 讨论(0)
提交回复
热议问题