【发布时间】:2013-12-13 04:42:21
【问题描述】:
我正在使用 asp.net 4.5 和最新的 MVC 版本。在 html 页面中发布表单时,我需要从标题中检索 deviceId 和 body。在public void Post([FromBody]string value) 行的值始终为空。
我在这里做错了什么?
namespace WebApi.Controllers
{
public class NotificationController : ApiController
{
// GET api/notification
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/notification/5
public string Get(int id)
{
return "value";
}
// POST api/notification
public void Post([FromBody]string value)
{
// value it is always null
}
// PUT api/notification/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/notification/5
public void Delete(int id)
{
}
}
}
<form action="/api/notification" method="post">
DeviceId: <input name="deviceId" value="gateeMachine">
Body: <input name="body" value="Warning Out of Paper">
<button>Tes send</button>
</form>
【问题讨论】:
标签: c# html asp.net-mvc