4

I tried to pass Array of javascript classes in $.post function, but in controller function, each member of 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(model) :

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 I can pass Array of javascript class into POST request and success retrieve it in controller ?

1 Answer 1

3

How to post an array of complex objects with JSON, jQuery to ASP.NET MVC Controller?

May be this will help

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.