1
Reply

Export to Excel using ViewModel and Repository - ASP.NET MVC

mike idowu

mike idowu

Dec 31 2017 12:58 PM
160
I have this model
 and ViewModel
 I want to export to Excel using ViewModel and Repository. Initially, I have used my Model Class and Repository, and it was working fine. But I want to change it to ViewModel and Repository. 
From the attached code, ExcelCode1 is the initial code I used that worked. How do I perform it using ViewModel.
 
How do I include ViewModel.
 
I tried to create a service as shown below and call from the controller, but dont know how to go about it.
 
 
 
ViewModel
public class CountriesViewModel
{
[HiddenInput]
public int COUNTRY_ID { get; set; }
[Required(ErrorMessage = "Country Code is required")]
[Display(Name = "Country Code")]
[StringLength(2, ErrorMessage = "The {0} must be at least {1} characters long. Plese check again!", MinimumLength = 2)]
public string COUNTRY_CODE { get; set; }
[Required(ErrorMessage = "Country Name is required")]
[Display(Name = "Country Name")]
[StringLength(100, ErrorMessage = "The {0} must be at least {1} characters long. Plese check again!", MinimumLength = 2)]
public string COUNTRY_NAME { get; set; }
}
 
 
 

Attachment: ExcelCode1.zip

Answers (1)