简体   繁体   English

在 JQuery 和 ASP.NET CORE 中发布 function 后表格未刷新

[英]Table not refreshing after post function in JQuery and ASP.NET CORE

I have made a filtering method.我做了一个过滤方法。 This method is working like a charm and when I type something the table updates to the search string.这个方法就像一个魅力,当我输入一些东西时,表格会更新为搜索字符串。 This is my method for the search:这是我的搜索方法:

loadList() {
var searchString = $(".search-input").val();
$.post('/Translation/List?searchString=' + searchString, function (data) {                      
$(".table-content-view").html(data);                    
});
}

And when I wanna insert a new record I call this method:当我想插入一条新记录时,我调用这个方法:

saveTranslation() {
                $.ajax({
                    url: '/Translation/Edit',
                    data: new FormData($(`${tr.selectedclass} #translation-form`)[0]),
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    success: function (response) {
                        if (response.success === true) {                        
                            loadList();
                        }
                    }
                });
            }

This method works fine (confirmed with postman and chrome dev tools).此方法工作正常(通过 postman 和 chrome 开发工具确认)。 The problem is I need to press F5 to see the new record instead that it refresh instantly.问题是我需要按 F5 来查看新记录,而不是立即刷新。 As you can see I call the method LoadList() to refresh the table but this doesn't work.如您所见,我调用方法LoadList()来刷新表,但这不起作用。

NOTE:笔记:

I use a partial view for the table.我对表格使用局部视图。

This is my C# method for the list:这是我的列表的 C# 方法:

[HttpPost]
public async Task<IActionResult> List(string searchString)
{       
    var translations = _context.translation.AsQueryable();
    translations = translations.OrderBy(x => x.CORETRANSLATIONID);

    if (!String.IsNullOrEmpty(searchString))
    {
           translations = translations.Where(x => x.ORIGINAL.Contains(searchString));
    }           
    return PartialView(await translations.ToListAsync());
}

Can someone point me in the right direction?有人可以指出我正确的方向吗?

In my post method in JQuery I changed it too在 JQuery 的post方法中,我也更改了它

saveTranslation() {
                $.ajax({
                    url: '/Translation/Edit',
                    data: new FormData($(`${tr.selectedclass} #translation-form`)[0]),
                    processData: false,
                    contentType: false,
                    type: 'POST',
                    success: function (response) {                      
                        loadList();
                    }
                });
            }

The if statement was not necessary. if 语句不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM