0
 if (saleDetails.length) {        
        var htmlData;
        var paymentStatus = 0;
        if ($('#PaymentStatus option:selected').val() != 0) {
            paymentStatus = $('#PaymentStatus option:selected').text()
        }
        var SaleAmount = parseFloat(total + vat).toFixed(2);
        var data = {
            'AccountID': $('#hdnAccountID').val(),
            'QuoteID': $('#hdnQuoteID').val(),
            'BranchID': $('#BranchID option:selected').val(),
            'PONO': $('#PONO').val(),
            'PaymentStatus': $('#PaymentStatus').val(),
            'SalesDate': $('#SaleDate').val(),
            'PaymentStatus': paymentStatus,
            'PaymentTypeID': $('#PaymentType option:selected').val(),
            'VAT': vat,
            'TotalAmount': invoiceAmount,
            'DiscountAmount': $('#discInput').val(),
            'AmountPaid': $('#amountPaid').val(),
            'SaleDetails': saleDetails
        };
        var json = JSON.stringify({ 'model': data });

public ActionResult printOrder(Models.DTO.Sales model)
        {
            return PartialView(model);
            //return View(model);            
        }

I am working on POS , In sales client requirement is that we should give him an option of print , so that if client click on Print button we should open a new tab and show invoice , so client can take out print and if customer pay him then client will save SalesOrder. The problem I am facing is that I am unable to open new tab from controller . And if I am trying to do this from java script I am unable to pass model to view from java script. So please help me in this issue as I am not too much expert in MVC.

1 Answers1

0

You can use Html.ActionLink to open the page in new tab from your Razor page as below.

@Html.ActionLink("Print", "Action", new { controller="PrintOrder" }, new { target="_blank" })

Html.ActionLink however does not allow you to pass complex objects. You can use trick as mentioned in this stackoverflow answer to pass your model. From the post:

MODEL: Make static Serialize and Deserialize methods in the class like

public class XYZ { 
  // Some Fields
  public string X { get; set; }
  public string Y { get; set; }
  public string X { get; set; }

  // This will convert the passed XYZ object to JSON string
  public static string Serialize(XYZ xyz)
  {
      var serializer = new JavaScriptSerializer();
      return serializer.Serialize(xyz);
  }

  // This will convert the passed JSON string back to XYZ object
  public static XYZ Deserialize(string data)
  {
      var serializer = new JavaScriptSerializer();
      return serializer.Deserialize<XYZ>(data);
  }
} 

VIEW: Now convert your complex object to JSON string before passing it in

Action View <%= Html.ActionLink(Model.x, "SomeAction", new { modelString = XYZ.Serialize(Model) })%>

CONTROLLER: Get the object as string in Action method and convert it back to object before

 using public ActionResult SomeAction(string modelString) { XYX xyz = XYX.Deserialize(modelString); }
Ankit Vijay
  • 3,752
  • 4
  • 30
  • 53