我试图在 $。post 函数中传递 Array 的javascript类,但在控制器函数中,list(参数)的每个成员都有默认值。
JS代码(查看)。
function CashCollectionModel()
{
this.Nominal = 0;
this.NominalCount = 0;
this.CriticalBalance = 0;
}
function SendRequest()
{
var arr = new Array();
var cash_nominal = new CashCollectionModel();
cash_nominal.Nominal = 10;
cash_nominal.NominalCount = 100;
cash_nominal.CriticalBalance = 20;
arr.push(cash_nominal);
$.post('<%= Url.Action("EditCashCollection", "Terminals") %>',
{
nominals : arr
});
}
服务器代码(型号):
namespace TerminalsExtension.Presentation.Models
{
public class CashCollectionModel
{
public long Nominal {set;get;}
public long NominalCount {set;get;}
public long CriticalBalance {set;get;}
}
}
控制器功能
public partial class TerminalsController : SharedControllerBase
{
[Authorize]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult EditCashCollection(List<CashCollectionModel> nominals)
{
// each member of "nominals" has 0 value
return ExtView("CashCollection");
}
}
如何将javascript类的 Array 传递给POST请求并成功在控制器中检索它?
答案 0 :(得分:3)