[英]working with MVC3 and c#,calling partial views from controller
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#. 任何人都可以建议使用带有剃刀视图和C#的MVC3进行此工作的最佳实践是什么。 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.
我要做的是有一个“顶层”模型,例如StudentModel,然后有其他“内部”模型,例如EnrolledStudentModel等。然后,我在所有构建标记的模型上都有一个称为GenerateUI()的方法。
The top-level model GenerateUI() simply does something like: 顶级模型GenerateUI()的作用类似于:
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. 然后依次UnenrolledStudentModel.GenerateUI()检查注册是否已打开,并返回一个表格,否则仅显示div表示注册已关闭或类似。
That's the approach I would take. 那就是我要采取的方法。 Hope it helps
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.