samedi 1 novembre 2014

How to return a specific view based on user input in ASP.NET MVC


Vote count:

0




I am fairly new to MVC, but not web programming and I am having an issue with passing data values from a View to a Controller where the data values are not associated with a Model.


Scenario: I have two types of users: Student and Faculty; Basically I am trying to determine which view to return when users register on the site.


EX:



public ActionResult Preregister(bool fac, bool stud)
{

if (stud == true)
{
return StudentRegister();
}
else if(fac == true)
{
return FacultyRegister();
}
else
{
return Index();
}
}


So, I want this ActionMethod called from this form:



@{
ViewBag.Title = "Preregister";
}

<h2>Registration</h2>
<p>Please indicate whether you are a student or faculty.</p>
@{
bool chkValFac = false;
bool chkValStud = false;
}
@using (Html.BeginForm("Preregister, Account"))
{
<div class="pre-reg-container">
<div class="checkbox-container">
<div class="item">
<label for="Student" style="width:70px;">Student</label>
@Html.CheckBox("Student", chkValStud)
</div>
<div class="item">
<label for="Faculty" style="width:70px;">Faculty</label>
@Html.CheckBox("Faculty", chkValFac)
</div>
</div>
<input name="continue" type="submit" id="continue" value="Continue" />
</div>
}


In debugging, I get this error:


The parameters dictionary contains a null entry for parameter 'stud' of non-nullable type 'System.Boolean' for method 'System.Web.Mvc.ActionResult Preregister(Boolean)' in 'Room_Booking_System.Controllers.AccountController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters


I don't understand how I can get the data from this view into the controller without posting back. I want a simple redirect based on the response. Please Help.


Thank you all!



asked 16 secs ago







How to return a specific view based on user input in ASP.NET MVC

Aucun commentaire:

Enregistrer un commentaire