ASP.net MVC 4.0: Send data from view to controller by three ways

1. By html

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>entryformhtml</title>
</head>
<body>
    <div>
        <fieldset style="width:400px; margin:auto">

        <legend>Enter  Employee Data Please</legend>


       <form action="\home\Index" method="post">
            <table>
                <tr>
                    <td>
                        Enter  Code
                    </td>
                    <td>
                       <input type="text" name="ecode" />
                    </td>
                </tr>
                <tr>
                    <td>
                       Enter Name
                    </td>
                    <td>
                       <input type="text" name="ename" />
                    </td>
                </tr>
                <tr>
                    <td>
                       Enter Department
                    </td>
                    <td>
                       <input type="text" name="edept" />
                    </td>
                </tr>
                <tr>
                    <td>
                      Enter Salary
                    </td>
                    <td>
                      <input type="text" name="esal" />
                    </td>
                </tr>
                <tr><td><input type="submit" /></td></tr>
            </table>
           </form>
        
            </fieldset>
    </div>
</body>
</html>

2. By Classic asp

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>entryform</title>
</head>
<body>
    <div>
       <fieldset style="width:300px; margin:auto">
       <legend>Enter  Employee Data Please</legend>
        <% using (Html.BeginForm("Index", "Home", FormMethod.Post))
       {         
       %>  

         Enter  Code <%=Html.TextBox("ecode")%>
        <br />
        Enter  Name<%=Html.TextBox("ename")%>
        <br />
        Enter  Department <%=Html.TextBox("edept")%>
        <br />
        Enter  Salary <%=Html.TextBox("esal")%>
        <input type="submit" />
       <%        
       }  
       %>
        </fieldset>   
            
    </div>
</body>
</html>


3. By Razor

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>entryformcshtml</title>
</head>
<body>
    <div>
    <fieldset style="width:400px; margin:auto">

        <legend>Enter  Employee Data Please</legend>

        @using (Ajax.BeginForm("Index", "Home", new AjaxOptions { UpdateTargetId = "divresult" }))
{
            <table>
                <tr>
                    <td>
                        @Html.Label("Enter  Code")
                    </td>
                    <td>
                        @Html.TextBox("ecode")
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("Enter Name")
                    </td>
                    <td>
                        @Html.TextBox("ename")
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("Enter Department")
                    </td>
                    <td>
                        @Html.TextBox("edept")
                    </td>
                </tr>
                <tr>
                    <td>
                        @Html.Label("Enter Salary")
                    </td>
                    <td>
                        @Html.TextBox("esal")
                    </td>
                </tr>
                <tr><td><button>submit</button></td></tr>
            </table>
        }
            </fieldset>
    </div>
</body>
</html>


Models

employee.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace mvctest.Models
{
    public class employee
    {
        public int ecode { get; set; }
        public string ename { get; set; }
        public string edept { get; set; }
        public int esal { get; set; }


    }
}

Controllers

HomeControllers.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mvctest.Models;

namespace mvctest.Controllers
{
    public class homeController : Controller
    {
        //
        // GET: /home/
      
        public ActionResult Index()
        {
            employee e = new employee();
            e.ecode = Convert.ToInt16(Request["ecode"]);
            e.ename = Request["ename"];
            e.edept = Request["edept"];
            e.esal = Convert.ToInt16(Request["esal"]);
            return View(e);
        }
        public ActionResult entryformhtml()
        {
                     return View();
        }
        public ActionResult entryformaspx()
        {
            return View();
        }
        public ActionResult entryformcshtml()
        {
            return View();
        }

    }
}


Output Here

1 2