Requred现场验证MVC [英] Requred field validate MVC

查看:74
本文介绍了Requred现场验证MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种情况。

我有一个 A型 B型。两者的形式使用一个单一的模式。有模型10个字段,所有字段是强制性的(必需)。

I have a form A and form B. both of the forms uses a single model. there are 10 fields in the model, all of the fields are Mandatory(Required)..

A型采用前5 (1,2,3,4,5)的模型和表格B用户的领域,其余(6 ,7,8,9,10)字段。

Form A uses first 5 (1,2,3,4,5) fields of the models and Form B user the remaining (6,7,8,9,10) fields.

所以,当我提交 A型它要求我为必填字段(6,7,8,9,10)来填补,同样是用 B型,它要求我要(1,2,3,4,5的情况下须提供)字段。我如何才能确保只有那些领域被认为需要哪些可用的形式。

So, when I submit form A it asks me for the required fields (6,7,8,9,10) to be filled and the same is the case with form B, it asks me for (1,2,3,4,5) field to be provided. how can I make sure that only those field are considered required which are available on the Form.

推荐答案

这是通过使用视图模型可能使你的观点将与相关视图模型交互,然后查看模型与模型进行交互。请记住,查看模型只包含字段相关的特定模型。因此,这里有步骤

This is possible by using View Models so your views will interact with relevant view model and then view model will interact with model. Keep in mind that view models contain only fields relevant specific to model. SO here are steps

1)使两种查看模式带有字段(1,2,3,4,5)和B场(6,7,8,9,10)

1) Make two view models A with fields (1,2,3,4,5) and B with fields(6,7,8,9,10)

2)的意见将提交相关领域他们的视图模型,那么你可以提交两种方式来模拟。

2) Views will submit relevant fields to their view models then you can submit to model in two ways

a)在提交视图A插入第一个五年值并插入未来五场
      伪晶片或默认值。当视图B提交再更新此记录的最后一次
五个值与实际值。

a) On submission of View A Insert first five values and insert next five fields with dummy or default values. And when View B is submitted then Update this record's last five values with actual values.

b)以包含所有十个字段而无需属性的另一个ViewModelAB,使此ViewModelAB的对象并填写上提交两个视图模型(即A和B)的。当所有的领域都充满然后提交到实际的数据库模型

b) Make another ViewModelAB containing all ten fields without required attribute, Make an object of this ViewModelAB and fill it on the submission of both View Models (i.e. A and B). When all the fields are filled then submit it to actual database model

请询问您是否需要进一步的帮助

Please ask if you need further assistance

这篇关于Requred现场验证MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆