我已经开始学习restful API,需要一些动力方面的指导。谢谢,我正在尝试将数据存储到SQL服务器中,这是通过URL从Android获取的。我使用的是在visual studio中使用MVC4和实体框架创建的restful API。下面的URL用于获取数据
http://localhost/finalWebAPI/api/Location/ahmad%6078.000%6089.000
我想在ahmad之后保存拆分字符串的值。以下代码是model类中的数据模型
public class locationdata
{
public static AndroidDBEntities2 db = new AndroidDBEntities2();
public static string locationcordinates(string name){
if (name != null) {
string[] str = name.Split('%');
string name1 = str[0];
string id1 = str[1];
string id2 = str[2];
user u = (from u1 in db.users
where u1.user_name ==name1
select u1).First();
u.lag = id1;
u.lng = id2;
db.SaveChanges() ;
}
return null;
}
这是控制器
public HttpResponseMessage Get(string id)
{
var reg1 = locationdata.locationcordinates(id);
// var employees = locationdata.UpdateEmployee(name,l);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, reg1);
return response;
}
路线如下
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
发布于 2015-12-09 22:02:52
请先看下面的链接:
http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api
http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-and-action-selection
默认情况下,web API路由到api/{ControllerNam}并获取HTTP方法以在控制器中选择正确的操作。默认情况下,此URL不指向任何控制器asp.net (localhost/finalWebAPI/api/Location/ahmad%6078.000%6089.000)路由。您必须将其更改为localhost/api/{ControllerNam}/6078.000%6089.000
https://stackoverflow.com/questions/34179525
复制相似问题