POST 500 (Internal Server Error) ajax,mvc

后端 未结 2 1699
一个人的身影
一个人的身影 2021-01-14 00:34

I have ajax request that sends data to my controller , it collects value of my dropdown

the error is

POST http://localhost:65070/form/create 500 (Int         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-14 01:21

    I have an example that I have used in my applications. In the controller, you must place

    [HttpPost]
    [ValidateAntiForgeryToken]
        public JsonResult Verificar(int idempleado, string desde, string hasta)
         {
          ...
         return Json(suiche, JsonRequestBehavior.AllowGet);
         }
    

    In the view, I have an ajax function

        function Verificar(desde, hasta) {
            var token = $('[name=__RequestVerificationToken]').val();
            var empleadoId = parseInt($('#empleadoId').val());
            var url = '/Settlements/Verificar';
            var settings = {
                "async": true,
                "crossDomain": true,
                "url": url,
                "method": "POST",
                "data": { __RequestVerificationToken: token, idempleado: empleadoId, desde: desde, hasta: hasta, }
            }
            $.ajax(settings).done(function (response) {
                if (response) {
                    $('#mensajefrom').text(null);
                    $('#mensajeto').text(null);
                } else {
                    $('#mensajefrom').text("There is another settlement with that date range");
                    $('#mensajeto').text("There is another settlement with that date range");
                }
            });
        }
    

    in the form, I use @Html.AntiForgeryToken()

提交回复
热议问题