[英]Redirect Page With JQuery In Asp.net Core
我在 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:標識符在數字文字之后立即開始
// 在谷歌瀏覽器中
未捕獲的 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>
}
Controller:
[HttpGet]
public IActionResult Test(string Id) {
return View();
}
啟動.cs:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//...
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.