1

I have a program where the user can register and log in, when the user is logged in, he gets a welcome message with his name and a question with two radio buttons. When the user select one of the radio buttons, I want him to be redirected to another razor view that shows a table with some information, and if he selects the other radio button, I want him to be redirected to another razor view that shows another table and in both of the tables he should be able to add different things to it using the database I’ve connected to it.

I am very new to programming overall, but I know the basics. My first question is, what do I need to accomplish to do this? What is the first thing I would need to do? I was thinking that I should make an if statement but it does not seem to work. I have created the radio buttons in the .cshtml. I have created one of the tables already in a separate controller with views. But how do I make that show based on which button the user chose?

I hope my question was clear. Thank you.

Yiyi You
  • 16,875
  • 1
  • 10
  • 22
  • 1
    https://stackoverflow.com/questions/546461/asp-net-mvc-redirect-to-a-different-view – devlin carnate Jul 11 '22 at 20:50
  • I know how to redirect to a different page normally, my question was how you can do it based on which button the user has selected. – Jessica Fredin Jul 11 '22 at 21:07
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 11 '22 at 22:04
  • See the answer by Mahender Reddy in the link I posted above. You can research how to determine which radio button a user selected. Then use that info to create your conditional statement. – devlin carnate Jul 11 '22 at 22:44

1 Answers1

0

If you want to redirect to different view,you can use js to redirect the page when the selected value changes.Here is a demo:

html:

<input type="radio" value="url1" name="redirect" />url1
<input type="radio" value="url2" name="redirect" />url2

js:

 <script>
        $("input[name='redirect']").change(function () {
            var value = document.querySelector('input[name="redirect"]:checked').value;
            if (value == "url1") {
                window.location.href = "/url1";
            } else {
                window.location.href = "/url2";
            }
        });
    </script>
Yiyi You
  • 16,875
  • 1
  • 10
  • 22