RADIO BUTTON REDIRECT

mathieu cupryk

Total Post:5

Points:35
Posted by  mathieu cupryk
 1369  View(s)
Ratings:
Rate this:

How can I fix the above so that :

if the user selects jobseeker redirect them to
JobSeeker/jsRegistration.cshtml otherwise go to
Employer/empRegistration.cshtml

 

<div class="wrap">
   
<div class="content">
        @Html.AntiForgeryToken()
       
<div class="box_title_h1">Are you a Job Seeker or an Employer?</div>
       
<form action="~/Registration/Registration" method="post">
           
<div class="inner-content" style="border:none">
               
<span><input type="radio" onclick="selecttype('jobseeker');" name="account" id="jobseeker" value="0"> I am a Job Seeker seeking WORK </span>
               
<span> <input type="radio" onclick="selecttype('employee');" name="account" id="employee" value="1"> I am a Company seeking to HIRE </span>
               
<input id="regtype" type="hidden" name="regtype" value="0" />
               
<span style="float:right">
                   
<input type="submit" class="home_buttonNext" value="Next Step">
               
</span>
               
<span style="clear:both"></span>
           
</div>
       
</form>
   
</div>
</div>

<script>

   
function selecttype(type) {

       
if (type == 'jobseeker') {

            $
('#regtype').val('0');
       
}
       
else {
            $
('#regtype').val('1');
       
}

   
}

</script>

  1. Chris Anderson

    Post:65

    Points:455
    Re: Radio Button Redirect

    In order to acheive this:

    create Controllers:

    public class JobSeekerController : Controller
    {
        public ActionResult jsRegistration()
        {
            return View();
        }
    }

    public class EmployerController : Controller
    {
        public ActionResult empRegistration()
        {
            return View();
        }
    }

    then modify your client script code as given below:

    function
    selecttype(type) {
           
    if (type == 'jobseeker') {
                $
    ('#regtype').val('0');
                window.location = "
    /JobSeeker/jsRegistration"
           
    }
           
    else {
                $
    ('#regtype').val('1');
               
    window.location = "/Employer/empRegistration"
            }
       
    }

    Hope this works for you.

  1. mathieu cupryk

    Post:5

    Points:35
    Re: Radio Button Redirect

    This looks great and makes sense.

    Should I create a controller these two controlers

    JobSeekerController.cs

    EmployerController .cs

    ?

  1. mathieu cupryk

    Post:5

    Points:35
    Re: Radio Button Redirect

    I also wanted to mention your article was really done nicely.

  1. mathieu cupryk

    Post:5

    Points:35
    Re: Radio Button Redirect

    <form action="~/Registration/Registration" method="post">
                <div class="inner-content" style="border:none">
                    <span><input type="radio" name="account" id="jobseeker" value="0"> I am a Job Seeker seeking WORK </span>
                    <span> <input type="radio" name="account" id="employer" value="1"> I am a Company seeking to HIRE </span>
                    <input id="regtype" type="hidden" name="regtype" value="0" />
                    <span style="float:right">
                        <input type="submit" class="home_buttonNext" value="Next Step">
                    </span>
                    <span style="clear:both"></span>
                </div>
            </form>

    I am not sure how to handle the form action?
    What should I have?

  1. Chris Anderson

    Post:65

    Points:455
    Re: Radio Button Redirect

    Yes you need to add two controller in Controller folder:

    JobSeekerController.cs
    EmployerController.cs


    In order to handle post requets you need to create action for post as given below:

    public class JobSeekerController : Controller
    {
        public ActionResult jsRegistration()
        {
            return View();
        }
       

        [HttpPost]
        public ActionResult jsRegistration(FormCollection form)
        {
            return View();
        }

    }

    public class EmployerController : Controller
    {
        public ActionResult empRegistration()
        {
            return View();
        }
       

        [HttpPost]
        public ActionResult empRegistration(FormCollection form)
        {
            return View();
        }

    }


    To hadle it from the view, modify the view code as given below:

    @using (Html.BeginForm())
     {
               <div class="inner-content" style="border:none">
                    <span><input type="radio" name="account" id="jobseeker" value="0"> I am a Job Seeker seeking WORK </span>
                    <span> <input type="radio" name="account" id="employer" value="1"> I am a Company seeking to HIRE </span>
                    <input id="regtype" type="hidden" name="regtype" value="0" />
                    <span style="float:right">
                        <input type="submit" class="home_buttonNext" value="Next Step">
                    </span>
                    <span style="clear:both"></span>
                </div>
     }

    Thanks.

  1. mathieu cupryk

    Post:5

    Points:35
    Re: Radio Button Redirect

    Fantastic I appreciate the help.
    I am getting into this mvc.

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: Radio Button Redirect

    Nice Answer.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!