简体   繁体   English

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

[英]Redirect Page With JQuery In Asp.net Core

I wrote some code in Asp .net Core At the bottom line I have a button that when clicked on it is directed to the Action Method by JQuery我在 Asp .net Core 中写了一些代码 在最后一行我有一个按钮,当点击它时,它会被 JQuery 定向到 Action Method

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

//J query //J查询

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

// Action Method // 动作方法

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

But when I click the button, I get this error但是当我点击按钮时,我得到了这个错误

//In the FireFox //在FireFox中

Uncaught SyntaxError: identifier starts immediately after numeric literal未捕获的 SyntaxError:标识符在数字文字之后立即开始

// In the Google Chrome // 在谷歌浏览器中

Uncaught SyntaxError: Invalid or unexpected token未捕获的 SyntaxError:无效或意外的令牌

For how to redirect to page by using Jquery,here is a working demo:关于如何使用 Jquery 重定向到页面,这里有一个工作演示:

View:看法:

<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>
}

Controller: Controller:

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

Startup.cs:启动.cs:

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

Result:结果: 在此处输入图像描述

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

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