Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

I've tried adding System.Runtime.Serialization namespace, which has Json class, but this particular instance of Json class doesn't have Encode method.

What assembly am I missing here?

Here is my exact code:

{ url: '@Url.Action("DeleteDefinitionRule")', editData: 
    { companyCode: 'LO', definitionID:@Html.Raw(Json.Encode(Model.DefinitionID)) } }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
627 views
Welcome To Ask or Share your Answers For Others

1 Answer

  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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...