Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过WebAPI+删除元素;jquery(ASP.NET核心)_Javascript_C#_Jquery_Asp.net Mvc_Asp.net Web Api - Fatal编程技术网

Javascript 通过WebAPI+删除元素;jquery(ASP.NET核心)

Javascript 通过WebAPI+删除元素;jquery(ASP.NET核心),javascript,c#,jquery,asp.net-mvc,asp.net-web-api,Javascript,C#,Jquery,Asp.net Mvc,Asp.net Web Api,我有asp.net webapi控制器 我有删除方法 这是控制器的代码 [HttpDelete("{id}")] public IActionResult Delete(Guid Id) { var reminder = _context.ReminderItems.Find(Id); if (reminder == null) { return NotFound(); }

我有asp.net webapi控制器 我有删除方法

这是控制器的代码

 [HttpDelete("{id}")]
    public IActionResult Delete(Guid Id)
    {
        var reminder = _context.ReminderItems.Find(Id);
        if (reminder == null)
        {
            return NotFound();
        }

        _context.ReminderItems.Remove(reminder);
        _context.SaveChanges();
        return NoContent();
    }
我尝试通过视图上的按钮和js函数删除它

function deleteItem(id) {
$.ajax({
    url: uri + '/' + id,
    type: 'DELETE',
    success: function (result) {
        getData();
    }
});
这里是js函数

function deleteItem(id) {
$.ajax({
    url: uri + '/' + id,
    type: 'DELETE',
    success: function (result) {
        getData();
    }
});
}

这是按钮代码
'Delete'

所以在渲染时,我得到了这个
Delete

当我单击时,控制台中出现错误,并且行未被删除

无效或意外的令牌

如果我试着从邮递员那里删除,用这个id可以吗


那么我的问题出在哪里呢?

你需要把你的id放在引号里,使它成为一个有效的javascript字符串:“编辑”当你显示的代码说onclick函数是editItem时,你的按钮onclick函数是如何神奇地呈现deleteItem的?是的,这很有效@J.洛斯科