سؤال

I need to get a count value from a MVC action after a prior MVC action has done some processing which is also ajax. The prior action is downloading a file.

So thoughts on JQuery is :

$(function () {
    $('#DownloadDoc').click(function () {

        $... // Call first process, works fine.
        $.ajax({
            url: "@(Url.Action("GetCount", "Controller"}, null))",
            success: function (intCount) {
                $("#divCount").html(intCount);
            }
        });            
        return true;
    });
});

I suspect the Action would look something like, bit fuzzy on this, so is incorrect syntax:

        public ActionResult GetCount()
        {
          int intCount = 1;
          Return intCount;
        }

I would really appreciate some clarification on the Action and JQuery syntax please.

Many thanks in advance.

هل كانت مفيدة؟

المحلول

Try like this,

$(function () {
    $('#DownloadDoc').click(function () {
        $.ajax({
            url: '@Url.Action("GetCount", "Controller")',
            success: function (intCount) {
                $("#divCount").html(intCount);
            }
        });            
    });
});

Controller

public JsonResult GetCount()
{
 int intCount = 1;
 return Json(intCount,JsonRequestBehavior.AllowGet);
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top