【发布时间】:2014-12-08 09:16:41
【问题描述】:
我是 asp.net 的初学者,在不使用实体框架的情况下使用 Web API 插入数据时遇到问题。我需要使用 API 将来自移动应用程序的数据存储在我的数据库中。数据将以 JSON 格式来自移动设备并需要插入数据库。 HttpPost 是用来做这个的吗?如果是,那将如何完成? 请帮我解决这个问题...
编辑 我使用此代码从数据库中获取数据...
HttpGet
public HttpResponseMessage aisleshelf(string ApiKey, string storeId = "")
{
headerParameter objheaderParameter = new headerParameter();
string Url = Convert.ToString(Request.RequestUri);
Url = Url.Replace("'", "''");
DBClass objDbclass = new DBClass();
DataSet ds = new DataSet();
string CustomerId = null, Description = null, Aisle = null;
Boolean UStatus = true;
Boolean ErrorStatus = false;
List<Aisle> objlistAisle = new List<Aisle>();
List<AisleShelf> objlistAisleShelf = new List<Models.AisleShelf>();
List<Aislelist> objlistAislelist = new List<Aislelist>();
Aislelist objAislelist = new Aislelist();
aisleshelfitem objaisleshelfitem = new aisleshelfitem();
int Code;
HttpResponseMessage response;
UserValid(ApiKey, Url, out UStatus, out CustomerId, out Code, out Description, UserIpAddress);
if (UStatus)
{
ds = objDbclass.AisleShelf(ApiKey, Url, out ErrorStatus, UserIpAddress, storeId);
// This will forward to my class where i wrtir a method to get data using stored procedure.
}
我需要创建一个 apicontroller 来插入数据。
查看这篇文章,其中数据通过 web 方法插入到数据库中。 http://www.webcodeexpert.com/2014/11/jquery-ajax-json-example-in-aspnet-to.html
现在在我的情况下,用户通过手机发送数据以调用我的 api 以将他的记录插入数据库。
【问题讨论】:
-
你有多少基础知识?在您的世界中,HttpPost 会如何神奇地出现在数据库中?您对您似乎对技术零了解的技术提出术语。
-
您是否尝试过任何方法,如果是,请分享代码,如果不了解更多详细信息,很难解决您的具体问题。您必须使用 HTTP POST 本身来创建新资源。
标签: c# json asp.net-mvc-4 asp.net-web-api