Reputation: 347
i have an application on mvc that have a controller with a post method
[HttpPost]
public EmptyResult(DispositivoMovil dispositivo)
{
try
{
//Something
}
}
And I have another silverlight application that need to use this method, how can i send a DispositivoMovil object to this method?
Upvotes: 1
Views: 513
Reputation: 1039298
You can't directly send an object to this controller from a Silverlight application. You need to send an HTTP POST request by using a WebClient for example and passing the values in the POST body. Here's an example:
var client = new WebClient();
var values = new NameValueCollection
{
{ "PropName1", "value 1" },
{ "PropName2", "value 2" },
{ "ComplexPropName3.SimpleProp", "value 3" },
// And so on for each value in the DispositivoMovil
};
client.UploadValuesCompleted += (sender, e) =>
{
byte[] result = e.Result;
// TODO: Do something with the response returned from the controller
};
client.UploadValuesAsync(new Uri("http://example.com/home/emptyresult"), values);
For more advanced binding scenarios you could take a look at this blog post.
Upvotes: 1