mvc 4 assembly reference missing for Json.Encode

后端 未结 3 586
谎友^
谎友^ 2020-11-30 07:47

I am trying to call a Json.Encode(...) method in MVC 4 and I\'m getting an error: The name \'Json\' does not exist in the current context.

相关标签:
3条回答
  • 2020-11-30 07:52

    Apparently if you create a new empty web project, and try and move everything into Areas, it removes the Helpers library. But if you create it as an internet project, they remain. I created a new project as an internet project and everything works now.

    0 讨论(0)
  • 2020-11-30 07:55
    1. References in solutions explorer > right click > Add reference
    2. Under Assemblies > Framework, search for "System.Web.Helpers" Double click
    3. System.Web.Helpers version 2.0.0.0 and click ok. Find the
    4. System.Web.Helpers you've just added > right click it > properties.
    5. Change "Copy Local" from false, to true

    And now @Json.Encode should work.

    Update

    enter image description here

    0 讨论(0)
  • 2020-11-30 08:00

    To be clear, even after you add the correct reference to your project, you still have to add this line at the top of your Razor page:

    @using System.Web.Helpers;
    
    0 讨论(0)
提交回复
热议问题