开发者

posting object to controller mvc2 from silverlight

i have an application on mvc that have a controller with a post method

[HttpPost]
public E开发者_如何学编程mptyResult(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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜