Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MVC 4 - jQuery - Complex type client-side post. Serverside result is instantiated but empty.

Status
Not open for further replies.

kristofdielis

Programmer
Sep 1, 2011
25
Hi,

I have a JS function that posts a contractcode + an array of a ComplexType to the server:

Code:
function PostContractServiceCatalogue(contractCode, lines) {
    var dto = { "contractCode": contractCode, "lines": lines };

    //prompt("", JSON.stringify(dto));

    $.ajax({
        type: 'POST',
        url: "/ContractServiceCatalogue/CreateSingleContractServiceCatalogueLines",
        dataType: "html",
        data: dto,
        success: function (returnPayload) {
            SetActionResultHtml(returnPayload);
            HideActionResult();
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert("request failed: " + thrownError);
        }
    });
}

If I uncomment that prompt I get this result:

Code:
{"contractCode":"CODE","lines":[{"Id":"97","Quantity":"-1","Price":"-1"},{"Id":"93","Quantity":"-1","Price":"-1"},{"Id":"94","Quantity":"10","Price":"10"},{"Id":"95","Quantity":"-1","Price":"-1"}]}

Content-wise that's correct and as far as I know it's also correct from a technical viewpoint.

Yet, at the Controller method, I get an object instance that is declared, but contains nulls. Code:

Code:
[HttpPost]
public ActionResult CreateSingleContractServiceCatalogueLines(UICreateSingleContractServiceCatalogue lines)
{
    var dtoActionResult = new DtoActionResult();

    return PartialView("BusinessActionResultDisplayer", dtoActionResult);
}

That UICreateSingleContractServiceCatalogue is defined like this:

Code:
public class UICreateSingleContractServiceCatalogue
{
    public string ContractCode { get; set; }

    public DtoNewContractServiceCatalogueLine[] Lines { get; set; }
}

So, I get a correct instance of this class, but with both ContractCode and Lines containing null.

-

I sort of broke it by adding the ContractCode, because before I did that the Lines array was filled in with a correct number of lines, though the values at server side were 0.

Any ideas on how to fix this? Thx.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top