Redirect to another view not working

Redirect to another view not working

navsnavyanavsnavya Posts: 19Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

**Case 1
**
$(document).ready(function (e) {
if (id == 'Yes') {
e.preventDefault();
window.location.href = '/Home/Yes/' + parseInt($(this).attr('data-field'));
}
else if (id == 'No;
window.location.href = '/Home/No/' + parseInt($(this).attr('data-field'));
}
});

**Case 2 **

$(document).ready(function (e) {
if (id == 'Yes') {
e.preventDefault();
window.location.href = '/Home/Yes/' + parseInt($(this).attr('data-field'));
}
else if (id == 'No;
window.location.href = '/Home/No/' + parseInt($(this).attr('data-field'));
}
alert(id + ' doc ready You clicked on button ' + datafie);
});

case 1 does not work, but case 2 does..How ever i want to get rid of alert message and redirect smoothly.

Replies

  • rf1234rf1234 Posts: 3,000Questions: 87Answers: 421

    That doesn't seem to be a Datatables related question. You are probably better off asking this on StackOverflow. Thanks.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Absolutely not a DataTables issue.
    However, in both cases your "else if (id == 'No;" condition is missing some brackets.

  • navsnavyanavsnavya Posts: 19Questions: 1Answers: 0

    ist is hold on im updating my sample code

  • navsnavyanavsnavya Posts: 19Questions: 1Answers: 0
    edited October 2022

    first row redirects, however second rows never redirects..

  • kthorngrenkthorngren Posts: 21,343Questions: 26Answers: 4,954

    The second button does more than nothing - you see the alert. The reason it doesn't redirect is due to the if statements:

        if (id==3){
           window.location.href = '/Home/Success/' + parseInt($(this).attr('data-field'));
        }
        if (id==1){
           window.location.href = '/Home/Failed/' + parseInt($(this).attr('data-field'));
        }
    

    The id of the second button is 2 so it won't match any of the if statements.

    Instead of using the id I would look assigning each type of button the same name or value. In the click event use the name or value to determine where to redirect. Take a look on Stack Overflow to see which option will work best for your solution.

    Kevin

  • navsnavyanavsnavya Posts: 19Questions: 1Answers: 0

    Thanks!!
    worked now ..i guess it was syntax

Sign In or Register to comment.