代码有效,但看着它以及可能需要增长的可能性让我感到担忧。是否可以将这3个单独的东西打包成对象并将它们传递给我的MVC控制器?
在此更新之前,它是一个简单的字符串数组,正在传递。
我必须使用window.open()
我已尝试使用其他各种方法做我需要做的事情,但这是唯一有效的方法。
以下是代码:
$('#print_quote').on('click', function (e) {
debugger;
// object one
var ProgramDescription_0 = $('#pricing-box-0 .pricing-box .pricing-title h3').text();
var PlanDescription_0 = $('#pricing-box-0 .pricing-box .pricing-title small').text();
var RetailCost_0 = $('#pricing-box-0 .pricing-price span').text();
var RateID_0 = $('#pricing-box-0 .pricing-price span').attr('id').replace('totalCost-', '');
// object 2
var ProgramDescription_1 = $('#pricing-box-1 .pricing-box .pricing-title h3').text();
var PlanDescription_1 = $('#pricing-box-1 .pricing-box .pricing-title small').text();
var RetailCost_1 = $('#pricing-box-1 .pricing-price span').text();
var RateID_1 = $('#pricing-box-1 .pricing-price span').attr('id').replace('totalCost-', '');
// object 3
var ProgramDescription_2 = $('#pricing-box-2 .pricing-box .pricing-title h3').text();
var PlanDescription_2 = $('#pricing-box-2 .pricing-box .pricing-title small').text();
var RetailCost_2 = $('#pricing-box-2 .pricing-price span').text();
var RateID_2 = $('#pricing-box-2 .pricing-price span').attr('id').replace('totalCost-', '');
var url = '@Url.Action("PrintComparison", "Quote", new { selectedPlans = "__plans__" })';
window.open(url.replace('__plans__', plans));
});
MVC控制器
public ActionResult PrintComparison(string ProgramDescription_0, string PlanDescription_0, string RetailCost_0, int RateID_0)
{
// Do stuff
}
是否可以将这些转换为对象并通过window.open
将它们传递给我的MVC控制器等待它们?
答案 0 :(得分:0)
填充您的数组以通过;
var arr = [];
arr.push({
ProgramDescription: "",
PlanDescription: "",
RetailCost: 0.00,
RateID: -1
});
通过POST调用您的方法
$.post('@Url.Action("PriceComparision", "Quote")', arr, function(html){
//use jqueryui Dialog Widget to display the resultant HTML
});