How to return a JSON object in standard web forms .Net

前端 未结 3 1238
逝去的感伤
逝去的感伤 2020-11-30 01:07

The objective is to call a method which does it\'s thing then returns a JSON object.

I\'m new to JSON.

I have a default.aspx and in it the following code. No

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 01:54

    Yes your method has to be static with the WebMethod attribute

    Basic example:

    CS

    using System;
    using System.Web.Services;
    
    public partial class _Default : System.Web.UI.Page
    {
      [WebMethod(EnableSession=false)]
      public static string HelloWorld()
      {
        return "Hello World";
      }
    }
    

    Javascript

    
    

提交回复
热议问题