[英]Why is my controller action returning 404?
I have a controller action called by an ajax call and it keeps returning a 404 error.我有一个由 ajax 调用调用的控制器操作,它不断返回 404 错误。
My Action:我的行动:
[HttpGet("~/TIB/Forms/GetGtmGrid")]
public IEnumerable<object> GetGtmGrid(int? id)
{
DataTable dtbl = new DataTable();
using (SqlConnection sqlConnection = new SqlConnection(_configuration.GetConnectionString("DB")))
{
sqlConnection.Open();
SqlDataAdapter sqlData = new SqlDataAdapter("usp_GetGTMNotesById", sqlConnection);
sqlData.SelectCommand.CommandType = CommandType.StoredProcedure;
sqlData.SelectCommand.Parameters.AddWithValue("Id", id);
sqlData.Fill(dtbl);
}
List<GTMNote> gtmNotes = new List<GTMNote>();
for (int i = 0; i < dtbl.Rows.Count; i++)
{
gtmNotes.Add(new GTMNote
{
Id = Convert.ToInt32(dtbl.Rows[i]["Id"]),
Text = dtbl.Rows[i]["Text"].ToString(),
ProjectId = Convert.ToInt32(dtbl.Rows[i]["ProjectId"]),
Date = (DateTime)dtbl.Rows[0]["Date"],
StatusId = Convert.ToInt32(dtbl.Rows[i]["StatusId"])
});
}
GTMNote[] gtmArray = gtmNotes.ToArray();
return gtmArray;
}
AJAX call: AJAX 调用:
$.ajax({
url: "/TIB/Forms/GetGtmGrid",
type: "GET",
dataType: "json",
//Pass parameters to controller
data: { id: id }
})
Here is the 404 error link:这是404错误链接:
GET
https://localhost:<port>/TIB/Forms/GetGtmGrid?id=428
404获取
https://localhost:<port>/TIB/Forms/GetGtmGrid?id=428
404
Any help or suggestions are appreciated.任何帮助或建议表示赞赏。 My controller actions and ajax calls are set up like all my other ones and they work just fine.
我的控制器操作和 ajax 调用的设置与我所有其他的一样,它们工作得很好。
I figured out what was causing the issue.我弄清楚是什么导致了这个问题。 It was the routing, ("~/TIB/Forms/GetGtmGrid"), in the action verb I was using with my controller action.
这是我在控制器动作中使用的动作动词中的路由(“~/TIB/Forms/GetGtmGrid”)。 So I changed my action verb from [HttpGet("~/TIB/Forms/GetGtmGrid")] to [HttpGet] and it worked as expected.
所以我将我的动作动词从 [HttpGet("~/TIB/Forms/GetGtmGrid")] 更改为 [HttpGet] 并且它按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.