Introduction
This article shows how to create a simple Data Entry Form. Here we create a form for storing the details of a student.
The following is the procedure for creating the application.
Step 1
Create a Web API application as in the following:
- Start Visual Studio 2012.
- From the start window select "Installed" -> "Visual C#" -> "Web".
- Select "ASP.NET MVC4 Web Application" and click on the "Ok" button.

- From the "MVC4 Project" window select "Web API".

- Click on the "Ok" button.
Step 2
- In the "Solution Explorer".
- Right-click on the Model folder.
- Select "Add" -> "Class".
- Select "Installed" -> "Visual C#" and select class.

- Click on the "Add" button.
Add the following code:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Web;
- namespace DatEntryAPI.Models
- {
- public class StudentModel
- {
- [Required(ErrorMessage = "Id is required")]
- public string Roll_no { get; set; }
- [Required(ErrorMessage = "Please fill the name of student")]
- public string Std_Name { get; set; }
- [Required(ErrorMessage = "Please fill the address of student")]
- public string Address { get; set; }
- [Required(ErrorMessage = "Select your gender")]
- public bool? Gender { get; set; }
- [Required(ErrorMessage = "Fill the Contact Number")]
- public int Std_Contact { get; set; }
- }
- }
Step 3
In the Controller add some code:
- In the "Solution Explorer".
- Expend the "Controller" folder.
- Select the "HomeController".

Add the following code:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using DatEntryAPI.Models;
- namespace DatEntryAPI.Controllers
- {
- public class HomeController : Controller
- {
- [HttpGet]
- public ActionResult StudentForm()
- {
- return View();
- }
- [HttpPost]
- public ActionResult StudentForm(StudentModel student)
- {
- if (ModelState.IsValid)
- {
- return View("Display", student);
- }
- else
- {
- return View();
- }
- }
- }
- }
Step 4
Create two Views using the following, one is "StudentForm.cshtml" and the other is "Display.cshtml".
- In the "HomeController".
- Right-click on the "StudentForm" action method.


- Select "AddView". Click on the "Add" button.
Add the following code in the "StudentForm.cshtml".



Comments
Join the conversation! Your thoughts help the community grow.