Thursday, 30 December 2021

save employee information insert form design in asp.net mvc in tamil

 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. 

save date in mvc
save employee crud operation in mvc tamil



Step 1: Open previous session-5 video created project 
        
infinity coding tamizha
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)

AS
BEGIN
if exists(select * from tblEmployee where ID=@Id)
begin
update tblEmployee set Employee=@employee,Designation=@designation,Salary=@salary,Address=@address
where ID=@Id
end

else
begin

insert into tblEmployee(Employee,Designation,Salary,Address)
values(@employee,@designation,@salary,@address)
end

END




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))
                {

                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = "prInsertUpdateEmployee";

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@Id", model.ID);

                    cmd.Parameters.AddWithValue("@employee", model.Employee);
                    cmd.Parameters.AddWithValue("@designation", model.Designation);

                    cmd.Parameters.AddWithValue("@salary", model.Salary);
                    cmd.Parameters.AddWithValue("@address", model.Address);

                    cmd.Connection = con;
                    con.Open();

                   int affect=cmd.ExecuteNonQuery();
                    if(affect >0)

                    {
                        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 

save data in mvc
Run the Project get Result


Download Project Code:


More Details:











ASP.NET MVC Full Course | In Tamil

  Overview: In this article, we will learn ASP.NET MVC Full Course in Tamil. We can learn additionally C#, SQL,  Bootstrap ..etc.  Model Pop...