首页 新闻 会员 周边 捐助

mvc的手机接口,

0
悬赏园豆:10 [待解决问题]

我新建了一个手机的接口,代码是这样写的:

public JsonResult ProcessMsg(JObject msg)
{
JsonResult result = null;
string action = msg["action:"].ToString();

switch (action)
{
case "create":
result = ProcessOrderCreate(msg);
break;
case "query":
result = ProcessOrderQuery(msg);
break;
case "edit":
result = ProcessOrderEdit(msg);
break;
}

return result;
}

private JsonResult ProcessOrderCreate(JObject msg)
{
JToken msgdata = msg["yaadoomsgdata"];

IList<OrderDetail> detailorders = new List<OrderDetail>();
SalesOrder order = new SalesOrder();
string customerid = msgdata["customerid"].ToString();
decimal discount = msgdata["discount"].ToObject<decimal>();
DateTime delivertime = msgdata["delivertime"].ToObject<DateTime>();
JToken details = msgdata["details"];

int detailcount = details.Count();
decimal amount = msgdata["amount"].ToObject<decimal>();
string discounttype = msgdata["discounttype"].ToObject<string>();
decimal amount_dis = msgdata["amountdis"].ToObject<decimal>();
string remark = msgdata["remark"].ToObject<string>();
string consignee = msgdata["consignee"].ToObject<string>();
string conaddress = msgdata["conaddress"].ToObject<string>();
string conaddtel = msgdata["conaddtel"].ToObject<string>();
SalesOrderManager om = new SalesOrderManager();
om.CreateEntity(order);
OrderDetailManager dm = new OrderDetailManager();
for (int k = 0; k < detailcount; k++)
{
OrderDetail detail = new OrderDetail();
detail.OrderId = order.Id;
detail.CommodityId = details[k]["commodityid"].ToObject<string>();
detail.Price = details[k]["price"].ToObject<decimal>();
detail.Amount = details[k]["amount"].ToObject<decimal>();
detail.Count0 = details[k]["count0"].ToObject<int>();
dm.CreateEntity(detail);
}
var data=new {des="创建成功"};
var json = new {result=1,yaadoomsgdata=data };
JsonResult result = new JsonResult();
result.Data = json;
return result;
}

现在我要在视图中测试一下我写的这个手机接口,但是我不知道该怎么做,求各位大神。

maziran的主页 maziran | 初学一级 | 园豆:194
提问于:2013-07-29 10:38
< >
分享
所有回答(1)
0

刚好最近我也做过类似的一个项目,你可以试试使用 Google Chrome 的一个插件来测试服务端 API,

在 Chrome Store 里搜:rest console 即可。

kuacci | 园豆:204 (菜鸟二级) | 2013-07-29 10:48

能不能帮忙说一下如果我在项目的视图中编写代码该怎么做呢?

支持(0) 反对(0) maziran | 园豆:194 (初学一级) | 2013-07-29 11:13

@maziran: 

你 action 返回的是 Json 数据,所以可以使用 jQuery 在页面发送post请求,然后将数据填充至目标DOM块中即可。

支持(0) 反对(0) kuacci | 园豆:204 (菜鸟二级) | 2013-07-29 17:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册