2016-09-29 2 views
0

Ich möchte die Funktionalität, wenn ich auf mitPreis Schaltfläche AJAX Anruf muss mitPricing Vorlage von Aktionsmethode & wenn ich klicke ohne Preisangabe AJAX muss ohnePricing Vorlage aus erhalten Aktionsmethode.erhalten unterschiedliche Daten von Mvc Aktionsmethode auf Ajax Anruf für zwei verschiedene Tastenklicks

ich habe zwei Aktionslinks:

<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 von jedem dieser Taste Ajax Maßnahme im Anschluss wird aufgerufen:

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; 
    } 

in Reaktion dieser Ajax-Methode ruft Daten von meiner mvc Aktion der Controller-Methode welches ist wie folgt:

i Ich möchte die Funktionalität, dass, wenn ich auf mit Schaltfläche "Pricing" klicken Ajax-Aufruf mitPricing-Vorlage von Aktionsmethode & erhalten, wenn ich ohne Preisangabe klicken Ajax muss ohne Vorlage von Aktion Methode erhalten.

Wie kann ich das erreichen?

Antwort

3

Sie können einen weiteren Parameter verwenden, um Ihren Anruf zu differenzieren.

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; 
} 

so Ihre Aktion Änderungen:

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

und html wird:

<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

Danke, es funktioniert !!!!!! – rohit

Verwandte Themen