使用 MVC3 和 C#,从控制器调用部分视图
我想设计一个应用程序,我需要从用户生成一些部分视图。 我的申请 学生入学。
在部分视图中,用户需要使用单选按钮选择他们是新生还是已注册学生。 如果他是新生,我需要为其提供一份注册表格,如果此时无法注册,我需要生成一条消息,而不向他显示注册表格。 如果他是新学生,我需要向他展示不同的形式。
任何人都可以建议使用带有 razor view 和 c# 的 MVC3 来解决此问题的最佳实践是什么。 为新生和注册学生创建部分视图是个好主意吗?
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到过类似的情况,我是使用部分视图解决的。我所做的是拥有一个“顶级”模型,例如 StudentModel,然后拥有其他“内部”模型,例如 EnrolledStudentModel 等。然后,我在构建标记的所有模型上拥有一个名为 GenerateUI() 的方法。
顶层模型GenerateUI()简单地执行如下操作:
然后依次UnenrolledStudentModel.GenerateUI()检查注册是否开放并返回一个表单,否则只是一个div表示注册已关闭或类似。
这就是我会采取的方法。希望有帮助
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:
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