Silverlight的电网,MVC,HTTP POST [英] Silverlight, Grids, MVC, HTTP Post

查看:114
本文介绍了Silverlight的电网,MVC,HTTP POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用Asp.Net MVC 2和Silverlight(特别是从数据库显示信息并允许用户更新信息网格)来创建一个可编辑的网格。

I'm trying to create an editable grid using Asp.Net MVC 2 and Silverlight (specifically a grid that displays info from a db and allows users to update that info).

到目前为止,我已经成功地把一个Silverlight网格上的一个视图,使用的这个技术

So far I've managed to put a silverlight grid on an a view, using this technique

不过,我没有从银色的光网获取更新的数据的方式。反正是有得到这些值回发到我的控制器?

However I have no way of getting the updated data from the silver light grid. Is there anyway to get these values posted back to my controller?

我是pretty新Asp.Net MVC,我真的只使用Silverlight入门。

I'm pretty new to Asp.Net MVC and I'm really only getting started using silverlight.

感谢您的帮助!

推荐答案

您需要做的是序列化回JSON的第一件事情: -

The first thing you need to do is serialize back to JSON:-

(假设你的 MyItem 对象的ObservableCollection使用ToArray的())

(Assumption you use ToArray() on a ObservableCollection of MyItem objects)

 public string SerialiseToJSON(MyItem[] myItems)
 {
        //Create a stream to serialize the object to.
        MemoryStream ms = new MemoryStream();

        // Serializer the User object to the stream.
        DataContractJsonSerializer ser = new DataContractJsonSerializer(MyItem[]);
        ser.WriteObject(ms, myItemsArray);
        byte[] json = ms.ToArray();
        ms.Close();
        return Encoding.UTF8.GetString(json, 0, json.Length);
 }

现在,你可以使用 Web客户端类JSON字符串送回去。

Now you can use the WebClient class to send the JSON string back.

WebClient web = new WebClient();

web.UploadStringAsync(new Uri("/yourcontroller/jsonReceiver", UriKind.Relative));

现在我不知道MVC那么好,但我相信你可以注释一个控制器的操作方法,以便它可以接受JSON数据的HTTP POST,它会为你做的deserialisation。

Now I don't know MVC all that well but I believe you can annotate a controller action method so that it can accept a http POST of JSON data and it'll do the deserialisation for you.

这篇关于Silverlight的电网,MVC,HTTP POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆