Home > DeveloperSection > Forums > Radio Button Redirect
mathieu cupryk

Total Post:5

Points:35
Posted on    March-31-2014 6:32 PM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 7 Reply(s)
 1093  View(s)
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>



Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    April-01-2014 1:52 AM

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.

mathieu cupryk

Total Post:5

Points:35
Posted on    April-01-2014 7:16 AM

This looks great and makes sense.

Should I create a controller these two controlers

JobSeekerController.cs

EmployerController .cs

?


mathieu cupryk

Total Post:5

Points:35
Posted on    April-01-2014 7:17 AM

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


mathieu cupryk

Total Post:5

Points:35
Posted on    April-01-2014 8:34 AM

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

Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    April-02-2014 7:13 AM

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.

mathieu cupryk

Total Post:5

Points:35
Posted on    April-02-2014 12:33 PM

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

Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    April-03-2014 4:03 AM

Nice Answer.

Don't want to miss updates? Please click the below button!

Follow MindStick