Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i have a nested Model like

C#
public class CurrentTableField
   {
      public virtual TablesField OTablesField { get; set; }
      public virtual Lookup Olookup { get; set; }
      public virtual FrequencyRule OfrequencyRule { get; set; }
      public virtual FormulaRule OformulaRule { get; set; }
      public virtual LookupData OLookupDataList { get; set; }
   }


and i am using this model on my view but the problem is to pass this model from view to Controller action method like
C#
public ActionResult addTableFild(CurrentTableField oCurrentTableField)
       {
              //code goes here
       }


and i passing the data using
JavaScript
$(".primary-btn").click(function (event) {
        event.preventDefault();

        var check= @Html.Raw(val);
        $.ajax({
            type: 'post',
            url: "/Table/addTableFild/",
            data: JSON.stringify(check),
            contentType:'application/json',
            dataType: "json",
            success: function (data) {
                alert(data);
            }
        });
    });



But i getting null in oCurrentTableField in Action method


How i can do this?
Posted
Comments
Jameel VM 3-Jan-14 8:33am    
what is 'Val'? can you post the val values?
Vi(ky 3-Jan-14 10:59am    
var val = Json.Encode(Model);

1 solution

could you describe what are the different fields in the model that you are encoding?

One reason you would get null in oCurrentTableField is because the field names that you get from check (when to stringify) do not match with CurrentTableField class properties.
 
Share this answer
 
Comments
Vi(ky 4-Jan-14 3:28am    
This is my view containing fields...
What should i do to solve this problem?


@using (html.BeginForm(null, null, FormMethod.Post, new { id = "MyForm" }))
{

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