【问题标题】:Redirect Page With JQuery In Asp.net Core在 Asp.net Core 中使用 JQuery 重定向页面
【发布时间】:2020-11-30 19:03:35
【问题描述】:

我在 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();}   

但是当我点击按钮时,我得到了这个错误

//在火狐中

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

// 在谷歌浏览器中

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

【问题讨论】:

    标签: c# jquery asp.net ajax asp.net-core


    【解决方案1】:

    关于如何使用 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?}");
        });
    }
    

    结果:

    【讨论】:

      猜你喜欢
      • 2018-10-21
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 2021-09-27
      相关资源
      最近更新 更多