Radio Button Redirect

Total Post:5

Points:35
 1732  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. 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.

      Modified On Apr-04-2018 05:06:04 AM
  1. 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. Post:5

    Points:35
    Re: Radio Button Redirect

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

  1. 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?

      Modified On Apr-04-2018 04:58:20 AM
  1. 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.

      Modified On Apr-04-2018 04:57:51 AM
  1. Post:5

    Points:35
    Re: Radio Button Redirect

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

  1. 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!