2011-07-11 5 views
0

私はこのような私のmasterlayoutでActionLinkのを持っている:

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

私はこのようなアクションメソッドがあります。

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

や機能などをこれは:

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

私がリンクをクリックすると、警告は表示されません。しかし、私はこのように使用する場合:

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

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

それは動作します。なぜ最初に動作していないのかをお聞かせください。

+0

現れるものを教えてthis

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

をラップしてみてくださいあなたがいるかどうか確認するためにFirebugのか、他のブラウザのデバッガのようなものを使用しましたHTTPリクエストが作成されていますか?どこにエラーが報告されていますか? – Pointy

+0

firebugを使ってチェックするあなたのリンクの 'href'属性の値は何ですか? – Rafay

+0

@ 3nigma:linkはfirebugのhtmlウィンドウで次のようになります。Order Your Free Report 1 DotnetSparrow

答えて

0

のAjaxバージョン

$(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; 
     }); 
    }); 

はこれを試してみて、アラートが

+0

3nigma:上記のコードを試しましたが、警告は表示されません。 – DotnetSparrow

+0

更新された回答をお試しください – Rafay

関連する問題