Trying to Get Data using Ajax call to Controller method MVC My code Attached

前端 未结 2 1509
北恋
北恋 2021-01-28 18:23

I am calling jquery function on dropdown value change jquery method is ,

function MyFunction() {
    alert($(\'#DDlSurvey\').val());
    $.ajax({
        url: \"         


        
2条回答
  •  死守一世寂寞
    2021-01-28 18:37

    Your method in your controller is decorated with HttpPost, while in your ajax you have specified the type of your request is get . You can either change your method to get like this:

    [HttpGet]
    public JsonResult GetSelectedQuestion(int prefix)
    {
    }
    

    Or change your request type to post in your Ajax call:

    $.ajax({
        url: "@Url.Action("GetSelectedQuestion", "ConductSurveyController")",
        data: { prefix: $('#DDlSurvey').val() },
        type: "Post",
    

    Also the Controller is redundant in ConductSurveyController, you need to remove it and simply call it as ConductSurvey:

    url: '@Url.Action("GetSelectedQuestion", "ConductSurvey")',
    

提交回复
热议问题