Hi Team
I have a razor from the form, basically the logic once i click the span icon it must route me to the next page(page does exist). I have tried to use jquery to call the actioname and its controller name, but it was not routing me directly but loads and do nothing and there are no js conflict when inspecting the element from the browser.
// view.cshmtl
JavaScript
@model SHEQ_NCR.Models.CapturingForm
@{
ViewBag.Title = "SHEQ NCR Capturing Form";
var url = Url.Action("CorrectiveCreate", "Home");
}
SHEQ NCR Capturing Form
.icon {
font-weight: bold;
color: red;
}
.btn-red-icon {
background-color: transparent;
border: none;
padding: 0;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.btn-group {
display: flex;
justify-content: space-between;
align-items: center;
margin: 20px auto; /* Adjust margin as needed */
max-width: 300px; /* Adjust width as needed */
}
>
Switch Pages
>
$(document).ready(function () {
$('#rightButton').click(function () {
// Use the Razor-defined URL in the jQuery code
});
});
Amit MohantyRank #112 · 20K reputationPosted Mar 1, 2024, 12:40 AM EST
You can use the Razor-defined URL in the jQuery code:
$(document).ready(function () { $('#rightButton').click(function () { // Use the Razor-defined URL in the jQuery code window.location.href = '@url'; }); });Or
$(document).ready(function () { $('#rightButton').click(function () { // Use JavaScript to redirect to the desired URL window.location.href = '@Url.Action("CorrectiveCreate", "Home")'; }); });Jignesh KumarRank #91 · 22.9K reputationPosted Mar 1, 2024, 12:13 AM EST
Hello,
You can use below one to redirect to another page using Jquery,
$(document).ready(function () { $('#rightButton').click(function () { // Use the Razor-defined URL in the jQuery code // Example ControllerName is HomeController and actionMethod name Index // Your URL should be '/Home/Index' window.location.href = '/Home/Index'; }); });Abhishek YadavRank #217 · 11.3K reputationPosted Mar 1, 2024, 1:03 AM EST
$(document).ready(function () { $('#rightButton').click(function () { // Use the Razor-defined URL in the jQuery code // Example ControllerName is HomeController and actionMethod name Index // Your URL should be '/Home/Index' window.location.href = '/Home/Index'; }); });