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);
}
我正在POS上工作,在销售客户的要求是我们应该给他一个打印选项,这样如果客户点击打印按钮,我们应该打开一个新选项卡并显示发票,这样客户就可以打印出来,如果客户付钱给他,那么客户将保存SalesOrder。我面临的问题是我无法从控制器打开新选项卡。如果我尝试从 java 脚本执行此操作,我无法从 java 脚本将模型传递给视图。所以请在这个问题上帮助我,因为我在 MVC 方面不是太专家。
您可以使用 Html.ActionLink 从 Razor 页面在新选项卡中打开页面,如下所示。
@Html.ActionLink("Print", "Action", new { controller="PrintOrder" }, new { target="_blank" })
但是,Html.ActionLink
不允许传递复杂对象。您可以使用此堆栈溢出答案中提到的技巧来传递您的模型。从帖子:
MODEL:使类中的静态序列化和反序列化方法像
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); } }
查看:现在在传入之前将复杂对象转换为 JSON 字符串
Action View <%= Html.ActionLink(Model.x, "SomeAction", new { modelString = XYZ.Serialize(Model) })%>
控制器:获取 对象在Action方法中作为字符串,并将其转换回之前的对象
using public ActionResult SomeAction(string modelString) { XYX xyz = XYX.Deserialize(modelString); }