Donate

ASP.NET MVC (Add,Edit,Delete,View/View All) Example in C#

Original Source: Developer Resources

Just this evening, i modified an ASP.NET MVC example from Visual Basic.Net to C#. I also completed the steps and added some basic functionalities of my own. The database used is MS SQL Server 2008 and the data source is an ADO.NET Entity object.

Below are the screenshots:






Here is the snippet for the validation side in C#. This is not sophisticated:
protected void ValidateEmployee(Employee EmployeeToValidate)  
      {  
        if (EmployeeToValidate.EmployeeName == null)  
        {  
          ModelState.AddModelError("EmployeeName"  
  , "Employee name is required field.");  
        }  
       if (EmployeeToValidate.Department == null)  
        {  
           ModelState.AddModelError("Department"  
  , "Employee Department is required field.");  
        }  
        if (EmployeeToValidate.EmployeeSalary == null)  
        {  
          ModelState.AddModelError("EmployeeSalary"  
  , "Employee Salary is required field.");  
        }  
        if (EmployeeToValidate.Age == null)  
        {  
           ModelState.AddModelError("Age"  
  , "Employee Age is required field.");  
        }  
        if (EmployeeToValidate.Role == null)  
        {  
           ModelState.AddModelError("Role"  
  , "Employee Role is required field.");  
        }  
        if (EmployeeToValidate.Skillset == null)  
        {  
           ModelState.AddModelError("Skillset"  
  , "Employee Skillset is required field.");  
        }  
      } 

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid