开发者

alert not shown with $.getJSOn asp.net MVC3

I have a an actionlink in my masterlayout like this:

 @Html.ActionLink("Order Your Free Report 1", "CheckValue", "Product", null,new { id = "checkExists" })

I have an action method like this :

  public ActionResult CheckValue() {
            bool result = true;
            ViewData["checkCondition"] = true;
            return Json(result, JsonRequestBehavior.AllowGet);
        }

and function like this:

$(function () {
    $('#checkExists').click(function () {
     $.getJSON(this.href, function (result开发者_运维问答) {
            alert(result);
            if (result) {
                alert('the record exists');
            }           
        });
        return false;
    });
});

When I click the link, alert is not shown. But If I use like this:

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

        var condition =new Boolean('@ViewData["checkCondition"]');
        if (condition) {
            alert("message");
        }
   return false;
    });
});

It works. Please suggest why first one is not working ?


try wrapping this into $(this)

$(function () {
    $('#checkExists').click(function () {
     $.getJSON($(this).attr('href'), function (result) {
            alert(result);
            if (result) {
                alert('the record exists');
            }           
        });
        return false;
    });
});

the ajax version

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

       $.ajax({
         url: $(this).attr('href'),
         type:'GET',
         success: function (result) { ... },
         dataType: 'json',
         error:function(jqXhr,textStatus, errorThrown){
             alert("Oops ");
             alert(jqXhr.responseText);
             alert(jqXhr.status);
         }
            });
          return false;
        });
    });

try this and tell what alerts show up

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜