我是ASP.net的新手(以及一般的编程),我在构建Web API时遇到了麻烦.更具体地说,我需要在这两方面提供帮助:
DOCcontroller发布新文档(DOC表).EXT_GUID参数时遇到问题.当我试图发布时,我得到一个错误."无法将多个参数(doc和parentOwner)绑定到请求的内容."基本上这是一个简单的文档管理系统.我希望通过让用户从外部数据库(EXT_GUID字段)提供GUID作为过滤器/参数来获取/发布文档(DOC).每个文档可以有多个EXT_GUID,每个EXT_GUID可以有多个文档(DOC).您可以假设我们在http帖子之前填充了EXT_GUID字段.
这是DOCcontroller代码
//POST api/DOC
public HttpResponseMessage PostDOC(DOC doc, List<string> parentOwners)
{
if (ModelState.IsValid)
{
var parents = db.BIMs.Where(bx => parentOwners.Contains(bx.EXT_GUID));
foreach (var p in parents)
doc.Owners.Add(p);
db.DOCs.Add(doc);
db.SaveChanges();
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, doc);
response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = doc.Id }));
return response;
}
else
{
return Request.CreateResponse(HttpStatusCode.BadRequest);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模型设置 - EntityFramework codefirst东西
public class EXT
{
public int Id { get; set; }
public string EXT_GUID …Run Code Online (Sandbox Code Playgroud)