ASP.net MVC 4.0: submit & show data using Model and Strongly-typed view (Aspx)

1.  Add  model as

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace softaid.Models
{
    public class employee
    {
        public int ecode { get; set; }
        public String ename { get; set; }
        public String edept { get; set; }
        public Double salary { get; set; }
    }

}

2. Add Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using softaid.Models;
namespace softaid.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult AcceptData()
        {
        return View();
        }
        [HttpPost]
        public ActionResult ShowData(  employee  e)
        {
            return View(e);
        }

    }
}

3. Add View  AcceptData( Strongly-typed)

123

3.1 Strongly-types view for AcceptData.aspx

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

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>AcceptData</title>
</head>
<body>
    <div>
        <fieldset>
       <legend> Enter  Employee Data Please</legend>
        <% using (Html.BeginForm("ShowData", "Home", FormMethod.Post))
       {         
       %>  

         Enter  Code <%=Html.TextBox("ecode", Model)%>
        <br />
        Enter  Name<%=Html.TextBox("ename",Model)%>
        <br />
        Enter  Department <%=Html.TextBox("edept", Model)%>
        <br />
        Enter  Salary <%=Html.TextBox("salary", Model)%>
        <input type="submit" />
       <%
         
       } 
       %>

        </fieldset>
    </div>
</body>
</html>

4. Add View  ShowData( Strongly-typed)

123_2

 

4.1 Strongly-types view for ShowData.aspx

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

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>ShowData</title>
</head>
<body>
    <div>
        <fieldset>
            <legend> Here is your Submitted Data</legend>
                   Code ::<%= Model.ecode%><br/>
                   Name ::<%= Model.ename%><br/>
                   Department:: <%= Model.edept%><br/>
                   Job Category:: <%                        
                          
                           if(Model.salary>10000)
                           {
                           Response.Write("Class-A ");
                           }
                           else if (Model.salary > 5000)
                           {
                               Response.Write("Class-B ");
                           }
                           else
                           {
                               Response.Write("Class-C ");
                           }
                               
                               %>
             
</fieldset>
</div>
</body>
</html>

5. Run the project..

5.1

123_3

5.2

123_4