简体   繁体   中英

MVC3 call Ajax in Jquery for store value in database

I am creating MVC3 Application My view Page script code is-

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(function () {
        $('#btnClaimCheck').click(function () {
            var slvals = []
            $('input:checkbox[name=ChkCheckClaim]:checked').each(function () {
                if ($('#ClaimSelectStatus').val() == "XYZABCZ") {
                    alert("bikaner")

                    $.ajax({
                        url: '@Url.Action("CheckClaim")',
                        type: 'POST',
                       // data: { comment: $("#UpdatelabelName").val(prompt("Please Eenter Details","Rejected Without reason")) }
                        data: { comment: prompt("Please Enter Details", "Rejected Without reason")
                        }


                    });
                }
                else {
                    alert("other")

                }
            });

        });
    });                                                                                           
</script>

and my controler is -

   [HttpPost]
        public ActionResult CheckClaim(String comment)
        {
                return View();
           }

its working and breakpoint hit on controler method but inside controler when i try to call any method from model then it can't hit the controller method and not show any error .

This is not a good place for the prompt.
even though it is working http://jsfiddle.net/j6PVm/1

Please replace it with a string like

data: {comment : "mydata"}

this is just to see that the ajax is functioning.

in general the prompt should be outside of the $.ajax scope.

$('#btnClaimCheck').click(function () { var data = prompt("Please Enter Details", "Rejected Without reason");

$.ajax({
         url: '@Url.Action("CheckClaim")',
         type: 'POST',
         data: { comment: data}
      });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM