Validation in MVC using two model in single view

Posted by Ganeshjoshi under ASP.NET on 5/20/2013 | Points: 10 | Views : 991 | Status : [Member] | Replies : 2
I have classes like:

public class One
{
public string FirstName { set; get; }
public string LastName { set; get;
}
public class Two
{
public string Address { set; get; }
public string City { set; get;
}

public class Three
{
public One _One { set; get; }
public Two _Two { set; get;
}

and i wants to validate these fields in single view at the time of insert in mvc2 . plz kindly provided me solution of this query

Regards:
EmailId : ganeshjoshi.in@gmail.com




Responses

Posted by: Blessyjees on: 5/20/2013 [Member] Bronze | Points: 25

Up
0
Down
hi,

You can create a single view model for these classes and decorate the fields of these with data annotations and use this class in view. Then you can validate the model with view. If you need , write a function to separate the single model to three model.

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Ganeshjoshi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rabbil on: 5/21/2013 [Member] Starter | Points: 25

Up
0
Down
Hi !

You must use namespace :
System.ComponentModel.DataAnnotation ;


This namespace would let you validate in a single view at the time of insert.
For more info you can refer below links:

http://www.dotnetfunda.com/articles/article1842-how-to-validate-using-data-annotationmvc-tutorial-number-11.aspx

http://www.asp.net/mvc/tutorials/older-versions/models-%28data%29/validation-with-the-data-annotation-validators-cs

Let me know if any clarification is required.

"I cannot teach anybody anything. I can only make them think"~ Socrates
Thanks And Regards

Ganeshjoshi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response