【发布时间】:2012-04-30 12:25:59
【问题描述】:
我知道如何从我的 MVC 应用程序中获取 json 格式的数据(见下文)
public JsonResult Index()
{
return Json(db.Publications, JsonRequestBehavior.AllowGet);
}
create 方法会是什么样子?编辑?
我猜它看起来像下面这样
[HttpPost]
public void Create(Publication publication)
{
try
{
db.Publications.Add(publication);
db.SaveChanges();
}
catch
{
// what do I catch?
}
}
如果是这样,我的 JSON 调用会是什么样子?
(假设 Publication 类如下所示)
public class Publication
{
public int Id { get; set; }
public String Title { get; set; }
}
感谢任何帮助。
【问题讨论】:
标签: asp.net-mvc json entity-framework