【发布时间】:2015-05-14 06:44:19
【问题描述】:
对不起,我的英文不是很好,所以我会尝试用代码告诉大家我需要什么。在格式情况下,当我有2个模型时,我将创建2个控制器**(例如:用户/产品)** ,如下
var serializer = new JavaScriptSerializer();
var users= new users() { id = 1};
var jsonText = serializer.Serialize(users);
var client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:65370/");
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
StringContent content = new StringContent(jsonText, Encoding.UTF8, "application/json");
/////////////
var a = client.PostAsync("api/users", users, new JsonMediaTypeFormatter()).Result; (client)
var b = client.PostAsync("api/product", product, new JsonMediaTypeFormatter()).Result; (client)
然后当创建用户和产品控制器时,邮政编码应该如下所示
public IHttpActionResult Postusers(users aa) {} (服务器)
public IHttpActionResult Postproduct(product bb) {} (server)
我只想为上面创建 1 个控制器,如下所示
var b = client.PostAsync<users/product>("api/all", product, new JsonMediaTypeFormatter()).Result;(client)
public IHttpActionResult Post<T>(Object ForAll) where T : new() {} (server)
我该如何构建这个结构,请帮我解决这个严肃的问题,谢谢
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework generics asp.net-web-api