0

I am new to .Net MVC. I am trying to send some data from my view to the controller.

Controller Code:

    [HttpPost]
    public ActionResult Add(string json)
    {
        //more code here
    }

JS:

function SaveDetails() {
     var details= {
    "Code": "test",
    "Desc": "Testing",
    "Xclude": "N"
};
$.ajax({
    type: "POST",
    async: true,
    url: "Add",
    contentType: 'application/json',
    dataType: "json",
    data: JSON.stringify(details),
    success: function (){
                $('#Code').val("");
                $('#Desc').val("");
                $('#Xclude')[0].checked = false;
    }
    });

}

But when I debug the code, the variable json in the controller is getting null value and not the data I am passing to it. I am not able to identify what is wrong here. Any help would be much appreciated.

1 Answer 1

1

Try:

data: {json:JSON.stringify(details)}

Otherwise MVC is going to expect the parameter name to be id.

Sign up to request clarification or add additional context in comments.

1 Comment

@Patrick...thanks for ur response...but even after the change the variable value is still null.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.