2016-09-29 1 views
0

withPricingボタンをクリックしたときにajax呼び出しがwithPricingテンプレートをアクションメソッド&から取得する必要がある機能が必要な場合ajaxをwithoutPricingテンプレートから取得する必要がありますアクションメソッド。2つの異なるボタンクリックでajax呼び出しで異なるデータを取得する

私は2つのアクションリンクを持っている:AJAXアクション以下、これらのボタンのいずれかの

<html> 
<body> 
<a id="print" name="withPrice" style="text-decoration:none;" onclick="callPrint('@item.Id');</a> 

<a id="print" name="withoutPrice" style="text-decoration:none;" onclick="callPrint('@item.Id');</a> 
</html> 
</body> 

のonclickに呼び出されます:応答で

function callPrint(item) { 
     var PrintCssContent = ""; 

     $.ajax({ 
      type: "GET", 
      url: '@Url.Action("GetHtmlString", "Itinerary", new { area = "Travel"})?tripid=' + item, 
      //data: item, 
      dataType: "text", 
      success: function (data) { 
       var parseData = JSON.parse(data); 
       alert(parseData.html); 

       var WinPrint = 
       window.open('', '', 'width=auto,height=auto,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes'); 

       WinPrint.document.write(parseData.html); 
       WinPrint.print(); 
      }, 
      error:function(){ 
       alert('error'); 
      } 
     }); 
     return false; 
    } 

このAjaxの方法は、私のMVCコントローラのアクションメソッドからデータを取得 次のようになります。

public ActionResult GetHtmlString(long tripId) 
{ 
string templateNameWithPricing =ConfigurationSettings.AppSettings["EmailTemplateBaseDirectoryWithPricing"].ToString(); 

string templateNameWithoutPricing = ConfigurationSettings.AppSettings["EmailTemplateBaseDirectoryWithoutPricing"].ToString(); 

tripService.SendPurchasedEmailForSpirit(objTravel, templateNameWithoutPricing, siteContext, ref htmlString, false, false, false, false, user); 

tripService.SendPurchasedEmailForSpirit(objTravel, templateNameWithPricing, siteContext, ref htmlString, false, false, false, false, user); 

return Json(new { html = htmlString }, JsonRequestBehavior.AllowGet); 
} 

i私がwithPricingボタンをクリックしたときにajax呼び出しがwithPricingテンプレートをアクションメソッド&から取得しなければならない機能が欲しい.Ajaxがアクションメソッドからテンプレートを取得しなければならない。

これをどのように達成できますか?

答えて

3

コールを区別するためにもう1つのパラメータを使用できます。

function callPrint(item, withOrwithout) { 
    var PrintCssContent = ""; 

    $.ajax({ 
     type: "GET", 
     url: '@Url.Action("GetHtmlString", "Itinerary", new { area = "Travel"})?tripid=' + item + '&withOrwithout=' + withOrwithout, 
     //data: item, 
     dataType: "text", 
     success: function (data) { 
      var parseData = JSON.parse(data); 
      alert(parseData.html); 

      var WinPrint = 
      window.open('', '', 'width=auto,height=auto,top=50,left=50,toolbars=no,scrollbars=yes,status=no,resizable=yes'); 

      WinPrint.document.write(parseData.html); 
      WinPrint.print(); 
     }, 
     error:function(){ 
      alert('error'); 
     } 
    }); 
    return false; 
} 

そうにあなたの行動の変更:

public ActionResult GetHtmlString(long tripId, string withOrwithout) 
    { 
     string templateName = ConfigurationSettings.AppSettings["EmailTemplateBaseDirectoryWithoutPricing"].ToString(); 

     if (withOrwithout == "withPrice") 
      templateName = ConfigurationSettings.AppSettings["EmailTemplateBaseDirectoryWithPricing"].ToString(); 

     tripService.SendPurchasedEmailForSpirit(objTravel, templateName, siteContext, ref htmlString, false, false, false, false, user); 

     return Json(new { html = htmlString }, JsonRequestBehavior.AllowGet); 
    } 

とhtmlは次のようになります。

<html> 
<body> 
<a id="print" name="withPrice" style="text-decoration:none;" onclick="callPrint('@item.Id', 'withPrice');</a> 

<a id="print" name="withoutPrice" style="text-decoration:none;" onclick="callPrint('@item.Id', 'withoutPrice');</a> 
</html> 
</body> 
+0

おかげで、それが働いています!!!!!! – rohit

関連する問題