Save employee details in bootstrap form design in asp.net mvc in tamil
Overview:
In this article we are going explain, how to save employee information insert form design in asp.net mvc using bootstrap. now we are going to create step by step in this article.
Step 1: Open previous session-5 video created project
open project insert update mvc already created. |
Step 2: Refer SQL store procedure for passing parameter
CREATE PROCEDURE [dbo].[prInsertUpdateEmployee]@Id int,@employee nvarchar(50),@designation nvarchar(50),@salary nvarchar(50),@address nvarchar(50)ASBEGINif exists(select * from tblEmployee where ID=@Id)beginupdate tblEmployee set Employee=@employee,Designation=@designation,Salary=@salary,Address=@addresswhere ID=@Idendelsebegininsert into tblEmployee(Employee,Designation,Salary,Address)values(@employee,@designation,@salary,@address)endEND
Step 3: add employee action method in mvc Home controller
{public ActionResult Employee()return View();}[HttpPost]{public ActionResult Employee(InsertUpdateModel model){try{using(SqlConnection con=new SqlConnection(constring))cmd.CommandText = "prInsertUpdateEmployee";SqlCommand cmd = new SqlCommand();cmd.Parameters.AddWithValue("@Id", model.ID);cmd.CommandType = CommandType.StoredProcedure;cmd.Parameters.AddWithValue("@designation", model.Designation);cmd.Parameters.AddWithValue("@employee", model.Employee);cmd.Parameters.AddWithValue("@address", model.Address);cmd.Parameters.AddWithValue("@salary", model.Salary);con.Open();cmd.Connection = con;if(affect >0)int affect=cmd.ExecuteNonQuery();ViewBag.Message = "Data saved successfully..!";{con.Close();}}}{catch(Exception ex)}throw new Exception(ex.Message);return View();
}
Step 4: Add View Page
@model InsertUpdateMVC.Models.InsertUpdateModel@{ViewBag.Title = "Employee";}<h2>Employee Information (Insert, Edit, Update, Delete and List)</h2>@Scripts.Render("~/bundles/jquery")@Scripts.Render("~/bundles/jqueryval")@Styles.Render("~/Content/css")<style>.error {color: white;background-color: #f12e2e;font-weight: bold;font-size: 12px;font-family: 'Times New Roman';position: static;display: inline-block;z-index: 5;}</style>@using (Html.BeginForm("Employee", "Home", FormMethod.Post)){<div class="container"><div class="row"><div class="col-lg-3">@Html.LabelFor(Model => Model.Employee)</div><div class="col-lg-3">@Html.TextBoxFor(Model => Model.Employee, new { @class = "form-control" })</div><div class="col-lg-1">@Html.ValidationMessageFor(Model => Model.Employee, "", new { @class = "error" })</div></div><br /><div class="row"><div class="col-lg-3">@Html.LabelFor(Model => Model.Designation)</div><div class="col-lg-3">@Html.TextBoxFor(Model => Model.Designation, new { @class = "form-control" })</div><div class="col-lg-1">@Html.ValidationMessageFor(Model => Model.Designation, "", new { @class = "error" })</div></div><br /><div class="row"><div class="col-lg-3">@Html.LabelFor(Model => Model.Salary)</div><div class="col-lg-3">@Html.TextBoxFor(Model => Model.Salary, new { @class = "form-control" })</div><div class="col-lg-1">@Html.ValidationMessageFor(Model => Model.Salary, "", new { @class = "error" })</div></div><br /><div class="row"><div class="col-lg-3">@Html.LabelFor(Model => Model.Address)</div><div class="col-lg-3">@Html.TextBoxFor(Model => Model.Address, new { @class = "form-control" })</div><div class="col-lg-1">@Html.ValidationMessageFor(Model => Model.Address, "", new { @class = "error" })</div></div><br /><div class="col-lg-offset-4"><button type="submit" class="btn btn-primary" value="Save">Save</button></div></div>}@if (ViewBag.Message != null){<script type="text/javascript">{alert('@ViewBag.Message')}</script>}
Step 5 : Change Route Config
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Routing;namespace InsertUpdateMVC{public class RouteConfig{public static void RegisterRoutes(RouteCollection routes){routes.IgnoreRoute("{resource}.axd/{*pathInfo}");routes.MapRoute(name: "Default",url: "{controller}/{action}/{id}",defaults: new { controller = "Home", action = "Employee", id = UrlParameter.Optional });}}}
Step 6 : Run the Project
Download Project Code:
More Details: