Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am creating mvc application using web api i am inserting the customer detail in database using ajax call(jquery) i am routing my call to
"LeadCustomer/SaveClient"
in my controller. on jquery side i debugged my code in chrome browser i am able to populate Data1 which is JSON STRING but on controller side DATA1 is null any help is appreciated.json string is not null i debugged it

What I have tried:

JavaScript
function insertInformation(name, telephone, email, Gender, birthday, cityid, stateid, Token, stageid, riskProfile, createdBy) {
    //var Data1 = null;
    debugger;
    var Data1 = { CUSTOMER_NAME: name, MOBILE: telephone, EMAIL_ID: email, GENDER: Gender, DOB: birthday, CITY_ID: cityid, STATE_ID: stateid, TOKEN_ID: Token, STAGE_ID: stageid, CREATED_BY: createdBy, UPDATED_BY: Token };
    //Data1 = { CUSTOMER_NAME: name },

    alert(JSON.stringify(Data1));
    $.ajax({
        type: "POST",
        url: apiUrl + "LeadCustomer/SaveClient",
        data: JSON.stringify(Data1),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        async: true,
        headers: { "cache-control": "no-cache" },
        success: function (obj) {
            var result = obj;

            alert(result);
        },
        error: function (obj) {
            alert("error");
        }
    });
}
C#
public class LeadCustomerEntity
    {
           //Unique Token ID
       
        public string GENDER { get; set; }
        public string CUSTOMER_NAME { get; set; }
        public int MOBILE { get; set; }
        public string EMAIL_ID { get; set; }
        public string DOB { get; set; }
        public int STATE_ID { get; set; }
        public int CITY_ID { get; set; }
        public string CREATED_BY { get; set; }
        public string UPDATED_BY { get; set; }
        public string TOKEN_ID { get; set; }
        
        public string STAGE_ID { get; set; }

    }


C#
[HttpPost]
        [Route("LeadCustomer/SaveClient", Name = "SaveClient")]
        public IHttpActionResult SaveClient([FromBody] LeadCustomerEntity Data1)
        //public IHttpActionResult SaveClient(string CUSTOMER_NAME)
        {
            try
            {
               // SaveConfirmation items = OrderRepository.SaveOrder(Data);
                LeadCustomerMosl item = LeadCustomerRepository.LeadCustomerRegistration(Data1);
               // string item = "heelo world";
                return Ok(item);
            }
            catch (Exception ex)
            {
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                return Ok("Failed");
            }
        }
Posted
Updated 13-May-17 7:49am
Comments
vivvicks 9-May-17 6:29am    
does "alert(JSON.stringify(Data1));" return something?, if not u need to map each json element with class type

1 solution

When you are making ajax request you have written "url: apiUrl + "LeadCustomer/SaveClient","
You have missed to provide its url.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900