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
<button onclick="Go('d6c00401-b95c-443b-8e30-769e6b5f8e03')">Click</button>
//J query
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
Uncaught SyntaxError: identifier starts immediately after numeric literal
// In the Google Chrome
Uncaught SyntaxError: Invalid or unexpected token
For how to redirect to page by using Jquery,here is a working demo:
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:
[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?}");
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.