binhhtse binhhtse - 6 months ago 27
Ajax Question

pass value to controller by using ajax

I want to pass value from view to controller by using ajax.

<button onclick="addCommentByAjax()" >Save</button>



My script:


function addCommentByAjax() {
$.ajax({
type: "POST",
url: '/Survey/DoDetailSurvey',

data: {
choiceId: "1"
}


});
}



Controller:


[HttpPost]
public ActionResult DoDetailSurvey(SurveyViewModel model, string choiceId)
{
//
}



but choiceId always null

Answer
function addCommentByAjax() {
$.ajax({
    type: "POST",
    url: '/Survey/DoDetailSurvey?choiceId=1'
    }
});
}

You can also pass like this