Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using the below code to achieve my functionality but i am not getting the model in the controller. Please help on the below issue.

JavaScript
var productCalcaulationModel = {
       ProductId: $('input[attributeName="ProductID"]').val(),
       DealWorkFlowProductID: $('input[attributeName="WorkFlowID"]').val(),
       ExistingTariff: $('input[attributeName="Existing Rate"]').val(),
       CalculationAttributes: '',
       SimpleAttributes: simpleAttributes
   };

   $.ajax({
       url: '/Hermes/Deposit/Edit',
       type: 'POST',
       data: JSON.stringify(productCalcaulationModel),
       datatype: 'json',
       //contentType: "application/json;charset=utf-8",
       success: function (data) {
           PopulateDealWorkflowDepositsTable(data, 'tableDepositDeal', false, -1, -1);
       },
       error: function (x, y, z) {
           alertify.error(genericErrorMessage);
           $('#loaderSelectProducts').css('display', 'none');
       }
   });


C#
 [System.Web.Mvc.HttpPost]
        public JsonResult Edit(ProductCalculationModel model)
        {
//some code here for my functionality and returning the JsonResult

        }



C#
public class ProductCalculationModel
   {
       public int ProductId { get; set; }

       public decimal ProposedTariff { get; set; }

       public decimal ExistingTariff { get; set; }

       public IList<PriceableProductAttribute> CalculationAttributes { get; set; }

       public IList<Attribute> SimpleAttributes { get; set; }

       public string ClientSegment { get; set; }

       public string DepositRowID { get; set; }

       public int DealWorkFlowProductID { get; set; }

       public ProductCalculationModel() { }
   }



I am not getting the model in the Edit method which i am sending from the ajax Json.
Posted

1 solution

As you are doing HttpPost the following values:

C#
var productCalcaulationModel = {
       ProductId: $('input[attributeName="ProductID"]').val(),
       DealWorkFlowProductID: $('input[attributeName="WorkFlowID"]').val(),
       ExistingTariff: $('input[attributeName="Existing Rate"]').val(),
       CalculationAttributes: '',
       SimpleAttributes: simpleAttributes
   };



which are html controls gets set to empty as HTTP is a stateless protocol.

Try passing some dummy values hardcoded in the above parameters for testing purpose
 
Share this answer
 
v2
Comments
gonath 19-Mar-14 1:14am    
Hi Swapnil,
Thanks for your answer. Can you please explain me about the HttpPost and HttpGet with some example scenarios?
swapnil_jadhav 19-Mar-14 7:18am    
Checkout the following link: http://www.dotnet-tricks.com/Tutorial/aspnet/bPTF281212-Difference-between-HttpGet-and-HttpPost-Method.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900