【发布时间】:2013-07-25 10:35:03
【问题描述】:
我对 mvc web api 很陌生
我已经创建了一个 web api Post 方法,它接受一个对象类型“Bag”并返回一个 HTMLString,代码如下所示
public HtmlString PostBag(Bag bagofItem)
{
return Utility.PostBagDiscountedItem(bagofItem);
}
现在从我的网站我想从控制器 PostBag() 调用 API 方法 PostBag
如果有人可以告诉我如何做到这一点,我不知道该怎么做并且感激不尽
我的 Web 应用程序如下所示。
public class HomeController : Controller
{
private Bag _bag = new Bag();
private string uri = "http://localhost:54460/";
public ActionResult PostBag()
{
// would some one show me how to POST the _bag to API Method PostBag()
return View();
}
public class Bag
{
private static List<Product> _bag { get; set; }
public List<Product> GetBag ()
{
if (_bag == null)
_bag = new List<Product>();
return _bag;
}
}
【问题讨论】:
标签: asp.net-mvc asp.net-web-api