I need to send two objects to the post and update methods to a web API, I work with c#, webapi, mvc. He's not taking it.
var album = {
nombre: "PowerAge",
Fecha: "011/10/1979"
}
var user = {
Name: "Rick"
area: "operaciones"
}
$.ajax(
{
url: "samples/PostAlbum",
type: "POST",
contentType: "application/json",
data: JSON.stringify({ album: album, user: user }),
success: function (result) {
alert(result);
}
});
api
[HttpPost]
public IHttpActionResult PostAlbum(album item, user itemuser)
{
}
try using
As you will see in the json that you send, how it
data
should match the parameters of thewebapi
,that's why I defined
item
anditemuser
that match the parameters of the action you invoke.On the other hand, if it is webapi, the url should be:
api/samples
Defining the action is not necessary because with the verb
http
reaches. This applies if it is a controller that inherits fromApiController
, instead if it is a simple controller you should use:you let
@Url.Action()
from the view be the one who defines the url.