我新建了一个手机的接口,代码是这样写的:
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;
}
现在我要在视图中测试一下我写的这个手机接口,但是我不知道该怎么做,求各位大神。
刚好最近我也做过类似的一个项目,你可以试试使用 Google Chrome 的一个插件来测试服务端 API,
在 Chrome Store 里搜:rest console 即可。
能不能帮忙说一下如果我在项目的视图中编写代码该怎么做呢?
@maziran:
你 action 返回的是 Json 数据,所以可以使用 jQuery 在页面发送post请求,然后将数据填充至目标DOM块中即可。