0

I´m new with MVC. I´m using MVC4. I'm having an issue with a callback. If I alert before and after the post() call both alerts show but the call doesn't fire.

[HttpGet]
[Authorize]
public ActionResult Dashboard(int Menu)
{
 //some code
 return View("Dashboard");
}

<script>
    $(document).ready(function () {
        $.post("../Client/GetFact", {},
        function (data) {  
          //some code
        });
    });
</script> 

[HttpPost]
[Authorize]
public JsonResult GetFact()
{
    //some code to fill object_data

    var data = object_data;

    return Json(data);
}

As long as I leave ActionResult Dashboard without a parameter is works. If I add a parameter to Dashboard(int Menu) then the call back to GetFact doesn't work. I searched and found a similar post and follow the instructions given by you guys, but still does not work( looked at: getJSON not working if the mvc model view controller has a parameter). I do not know what I'm doing wrong. Can you help? Thank's!

4

2 に答える 2

0

これは省略形のAjax関数であり、次のものと同等です。

$.ajax({  type: "POST",
           url: url,  
          data: data,
       success: success,// -> call alert here  
      dataType: dataType}); 
于 2013-01-29T15:40:26.657 に答える
0

URLの代わりに@Url.Actionでjqueryを使用して、$.getで同様のことを行います。

FormContext を使用して Action に渡すことに加えて:

@using (Html.BeginForm()) の直前に配置

@{ ViewContext.FormContext = new FormContext(); }

例 :

$.get('@Url.Action("ActionName", "ControllerName")', { IDName: $('#IdName').val() }, function (data) {
                    //Do Something here with the data
                });

私はフォームポストが

$.post('@Url.Ation("ActionName", "ControllerName")', function (data) {
                     //Do Something here with the data
              });
于 2013-01-29T15:57:35.467 に答える