Verwendung habe ich eine Methode in Controller-ASP.Net Web-API wie folgt -http POST von Körper mehrere Parameter
public string addNewTask([FromBody]TaskListModels _newTask)
{
DataTable _newTaskDataTable = new DataTable();
try
{
SQLHelper sqlHelper = new SQLHelper(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString.ToString());
sqlHelper.Parameters.AddWithValue("@taskId", _newTask.taskId);
//sqlHelper.Parameters.AddWithValue("@userId", userId);
sqlHelper.Parameters.AddWithValue("@taskDetails", _newTask.taskDetails);
sqlHelper.Parameters.AddWithValue("@companyId", _newTask.companyId);
sqlHelper.Parameters.AddWithValue("@dueDate", _newTask.dueDate);
_newTaskDataTable = sqlHelper.ReturnDataTableFromStoredProcedure("[dbo].[MYSP]");
}
catch (SqlException ex)
{
Console.WriteLine("SQL ERROR: " + ex.Message);
}
catch (Exception e)
{
Console.WriteLine("ERROR: " + e.Message);
}
return "String";
}
Wo TaskListModels ist eine Klasse mit einigen Eigenschaften wie folgt.
public class TaskListModels
{
public int taskId { get; set; }
public string userId { get; set; }
public string taskDetails { get; set; }
public int companyId { get; set; }
public string companyName { get; set; }
public string dueDate { get; set; }
}
Ich versuche, einige Daten aus einem Winkel Dienst zu schreiben wie folgt -
public addTask(_newTask: any) {
console.log('Service - TaskListService : Method - addTask : Params - ' + JSON.stringify(_newTask))
this._requestOptions = new RequestOptions({
method: RequestMethod.Post,
url: this.addNewtaskApiUrl,
headers: this.headers,
body: JSON.stringify(_newTask)
});
console.log('ADD New - POST Request Query : ' + JSON.stringify(this._requestOptions));
return this._http.request(new Request(this._requestOptions)).map(this._httpExtractDataService.extractData).catch(this._httpErrorHandlerService.handleError);
}
Die Daten im Browser-Konsole wie folgt angezeigt wird, aber es ist mein Controller-Methode trifft nicht -
POST Request Query : {"method":1,"headers":{"Content-Type":["application/json"]},"body":"{\"taskId\":4,\"taskDetails\":\"Working with Avi for accounting platform project setup\",\"companyId\":4,\"dueDate\":\"2017-05-16\"}","url":"http://localhost:56250/api/Dashboard/addNewTask","withCredentials":null,"responseType":null}
Jede Hilfe wäre willkommen.
Dank
Wo nennen Sie 'addTask'? – echonax
addTask ist ein Verfahren, in dem service.I es so in einer Komponente nennt - öffentliche updateTask (newtask: jeder) { \t \t \t this._taskListService.addTask (this.newTask); } –
wird die HTTP-Anfrage ausgelöst? siehst du es im Netzwerk-Tab deines Browsers? auch, dass ASP.NET 'addNewTask', ist es registriert als ein' POST' Endpunkt? –