I am looking for a feature where clicking on the 'withPricing' button triggers an ajax call to retrieve the withPricing template from the action method, and clicking on the 'without pricing' button retrieves the withoutPricing template.
I have two action links:
<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>
When either of these buttons is clicked, the following ajax action is triggered:
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;
}
Upon response, this ajax method retrieves data from my MVC controller's action method, which is as follows:
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 would like the functionality where clicking the 'withPricing' button fetches the withPricing template via ajax call from the action method, and clicking 'without pricing' button fetches the withoutPricing template. How can I implement this?