Search This Blog

Monday, 13 March 2017

Pass user defined object to ASP.NET Webmethod from jQuery, using JSON



In .html page
  <script>
        function StoreDataInDatabse() {
            debugger;
            var Employee_Detail = {}
            Employee_Detail.Emp_Name = "Test";
            Employee_Detail.Emp_Age = "24";
            Employee_Detail.Emp_Salary = "1000";
            Employee_Detail.Emp_City = "Ban";

            $.ajax({
                type: "POST",
                url: "default.aspx/Insert_Data",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
            data: JSON.stringify({ 'Employee_Detail': Employee_Detail }), // Check this call.
                success: function () {

                    alert("Data Has Inserted")
                }
            })
        }
    </script>

<div>
 <input type="button" id="btnSave" value="Save Data" onclick="StoreDataInDatabse()"/>
               
</div>

Default.aspx.cs file

[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static void Insert_Data(Employee_Detail Employee_Detail)
        {

        }

Class file
public class Employee_Detail
    {
        public string Emp_Name { get; set; }
        public string Emp_Age { get; set; }
        public string Emp_Salary { get; set; }
        public string Emp_City { get; set; }
    }

use same properties names in both places(client side and server side)

9 comments:

  1. AngularJS is a toolset for building the framework most suited to your application development. It is fully extensible and works well with other libraries. Every feature can be modified or replaced to suit your unique development workflow and feature needs. Read on to find out how.

    AngularJS Training in Chennai
    AngularJS Training Institute in Chennai

    AngularJS Certification Training in Chennai

    ReplyDelete
  2. Those guidelines additionally worked to become a good way to recognize that other people online have the identical fervor like mine to grasp great deal more around this condition
    Digital Marketing Training in Chennai

    Digital Marketing Training in Bangalore


    digital marketing training in annanagar



    ReplyDelete
  3. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
    full stack developer training in bangalore

    full stack developer training in online


    ReplyDelete
  4. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.

    full stack developer training in bangalore

    ReplyDelete
  5. I wish to show thanks to you just for bailing me out of this particular trouble.As a result of checking through the net and meeting techniques that were not productive, I thought my life was done.
    full stack developer training in pune

    ReplyDelete
  6. I am really happy with your blog because your article is very unique and powerful for new reader.
    Click here:
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune

    ReplyDelete
  7. This is a nice post in an interesting line of content.Thanks for sharing this article, great way of bring this topic to discussion.
    Click here:
    python training in annanagar
    Click here:
    python training in velachery

    ReplyDelete
  8. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    Blueprism online training

    Blue Prism Training in Pune

    Blueprism training in tambaram

    ReplyDelete
  9. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 

    Data Science Training in Chennai
    Data science training in bangalore
    Data science online training
    Data science training in pune

    ReplyDelete