我想通过一个asp.net核心api在数据库中创建一个地址对象。我使用Postman来调用该方法。asp.net核心Api - 在数据库中插入新行
类:
namespace LC.Tools.API.Controllers {
[Route("api/[controller]")]
public class MailerController : Controller
{
Data.LCToolsDbContext _context;
public MailerController(Data.LCToolsDbContext context)
{
_context = context;
}
[HttpPost]
public async Task<IActionResult> CreateAddress(int client, string name, string email)
{
Address adr = new Address() { ClientId = client, Name = name, Email = email };
_context.MailerAddresses.Add(adr);
await _context.SaveChangesAsync();
return Ok(adr);
}
} }
URL(使用POST):
http://localhost:50444/api/mailer/createAddress?client=1&name=test&[email protected]
我也有方法的破发点,但它从来没有击中。我没有收到任何错误消息,它只是没有做任何事情。
指定端点名称可以你展示视图? –
查看[URL编码](https://www.google.nl/search?q=URL+encoding)您的值。 @符号在URL中无效。使用%40,你会没事的。 –
为什么不传入'address'对象? – Izzy