0

So I have a controller takes strong typed CarModel object for post request. In angular js how do I serialize it and pass with post request so the controller will understand it. Can someone show a sample code or point to a right direction.

I have only seem people posting on how to pass data for angular js to read it, did not find anything talks about how to post a strong typed object.

Thanks

1 Answer 1

2
[HttpPost]
[Route("someUrl")]
public IHttpResult PostObject([FromBody]Type name){
    return Ok();
}

And from angular

$http.post("someUrl", myObject);

The javascript object is serialized by angular. The property names just have to match.

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

3 Comments

Got you Thank you very much. I am going to try it out tonight when I get home.
I have added ModelState.IsValid for validation. However, when "myObject" is null, it passed "Modelstate.IsValid" do you know why ?
@JakeZheng I have no idea what you're using as a validator. But, your object is not invalid. Please open a new thread with a new question.

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.