在Asp.net Core中使用JQuery重定向页面

问题描述

我在Asp .net Core中写了一些代码 在最后一行,我有一个按钮,当单击它时,它会通过JQuery定向到Action Method

<button onclick="Go('d6c00401-b95c-443b-8e30-769e6b5f8e03')">Click</button>

// J查询

function Go(Id){                                                                    
 $.get("/Users/Test/"+Id)
}

//动作方法

public IActionResult Test(string Id){return View();}   

但是当我单击按钮时,出现此错误

//在FireFox中

未捕获的SyntaxError:标识符在数字文字之后立即开始

//在Google Chrome浏览器中

未捕获到的SyntaxError:无效或意外的令牌

解决方法

有关如何使用Jquery重定向到页面的操作,这是一个有效的演示:

查看:

<button onclick="Go('d6c00401-b95c-443b-8e30-769e6b5f8e03')">Click</button>
@section Scripts
{
<script>
    function Go(Id) {
        $.get("/Users/Test/" + Id,function () {
            window.location.href = "Users/Test";
        })
    }
</script>
}

控制器:

[HttpGet]
public IActionResult Test(string Id) { 
    return View(); 
}

Startup.cs:

public void Configure(IApplicationBuilder app,IWebHostEnvironment env)
{
    //...
    app.UseRouting();
    app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
                name: "default",pattern: "{controller=Home}/{action=Index}/{id?}");
    });
}

结果: enter image description here

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...