I want to designing an application Where i need to generate some partial view from user . My application Students enrollment.
In a partial view user needs to select whether they are new student or Enrolled student using a radio button. If he is a new student i need to render a form for his enrollment,and if the enrollment is not available at this time,i need to generate a message without showing him the form for enrollment. if he is a new student i need to show him a different form.
Can anyone suggest what is the best practise to work on this with MVC3 with razor view and c#. is it a good idea for creating partial views for new and enrolled students.
I've had similar situations that I resolved using partial views. What I do is have one 'top-level' model, say StudentModel and then I have other 'inner' models, such as EnrolledStudentModel etc. I then have a method called GenerateUI() on all models that builds the markup.
The top-level model GenerateUI() simply does something like:
public string GenerateUI()
{
if(Student.IsEnrolled)
return EnrolledStudentModel.GenerateUI();
else
return UnenrolledStudentModel.GenerateUI();
}
Then in turn UnenrolledStudentModel.GenerateUI() checks if enrollment is open and returns a form otherwise just a div saying enrollment closed, or similar.
That's the approach I would take. Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.