Asp.net mvc - pass javascript class to POST request

I tried passing Array from javascript classes to the $ function . post , but in the controller function, each member of the list (argument) has default values.

JS code (view).

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 }); } 

Server code (models):

 namespace TerminalsExtension.Presentation.Models { public class CashCollectionModel { public long Nominal {set;get;} public long NominalCount {set;get;} public long CriticalBalance {set;get;} } } 

Controller function

 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"); } } 

How can I pass an array from a javascript class to a POST request and get it in the controller?

+4
source share

Source: https://habr.com/ru/post/1341778/


All Articles