Posted by : sinhalamp3 Sunday, October 11, 2015

Create Student

Controller

DekmaEntities _dekmaEntities;

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Create()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Create(Student student)
        {
            using (_dekmaEntities = new DekmaEntities())
            {
                _dekmaEntities.Students.AddObject(student);
                _dekmaEntities.SaveChanges();

                return View("Index");
            }

        }

public ActionResult ViewAll()
        {
            using (_dekmaEntities = new DekmaEntities())
            {
                var stu = _dekmaEntities.Students.Take(10).ToArray();
                List studentList = new List();

                for (int i = 0; i < stu.Length; i++)
                {
                    Student student = new Student();
                    student.Student_ID = stu[i].Student_ID;
                    student.Name = stu[i].Name;

                    studentList.Add(student);
                }

                return View(studentList);
            }
        }
---------------------------------------------------------------------------------------------

Views

---
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>


Create




   

Create



    <% using (Html.BeginForm()) {%>
        <%: Html.ValidationSummary(true) %>

       

            Fields
           
           

                <%: Html.LabelFor(model => model.Student_ID) %>
           
           

                <%: Html.TextBoxFor(model => model.Student_ID) %>
                <%: Html.ValidationMessageFor(model => model.Student_ID) %>
           
           
           

                <%: Html.LabelFor(model => model.Name) %>
           
           

                <%: Html.TextBoxFor(model => model.Name) %>
                <%: Html.ValidationMessageFor(model => model.Name) %>
           
           
           

                <%: Html.LabelFor(model => model.House) %>
           
           

                <%: Html.TextBoxFor(model => model.House) %>
                <%: Html.ValidationMessageFor(model => model.House) %>
           
           
           

                <%: Html.LabelFor(model => model.street) %>
           
           

                <%: Html.TextBoxFor(model => model.street) %>
                <%: Html.ValidationMessageFor(model => model.street) %>
           
           
           

                <%: Html.LabelFor(model => model.City) %>
           
           

                <%: Html.TextBoxFor(model => model.City) %>
                <%: Html.ValidationMessageFor(model => model.City) %>
           
           
           

                <%: Html.LabelFor(model => model.Gender) %>
           
           

                <%: Html.TextBoxFor(model => model.Gender) %>
                <%: Html.ValidationMessageFor(model => model.Gender) %>
           
           
           

                <%: Html.LabelFor(model => model.Birth_day) %>
           
           

                <%: Html.TextBoxFor(model => model.Birth_day) %>
                <%: Html.ValidationMessageFor(model => model.Birth_day) %>
           
           
           

                <%: Html.LabelFor(model => model.NIC) %>
           
           

                <%: Html.TextBoxFor(model => model.NIC) %>
                <%: Html.ValidationMessageFor(model => model.NIC) %>
           
           
           

                <%: Html.LabelFor(model => model.Tel_land) %>
           
           

                <%: Html.TextBoxFor(model => model.Tel_land) %>
                <%: Html.ValidationMessageFor(model => model.Tel_land) %>
           
           
           

                <%: Html.LabelFor(model => model.Tel_mobile) %>
           
           

                <%: Html.TextBoxFor(model => model.Tel_mobile) %>
                <%: Html.ValidationMessageFor(model => model.Tel_mobile) %>
           
           
           

                <%: Html.LabelFor(model => model.Stream) %>
           
           

                <%: Html.TextBoxFor(model => model.Stream) %>
                <%: Html.ValidationMessageFor(model => model.Stream) %>
           
           
           

                <%: Html.LabelFor(model => model.Ex_Center) %>
           
           

                <%: Html.TextBoxFor(model => model.Ex_Center) %>
                <%: Html.ValidationMessageFor(model => model.Ex_Center) %>
           
           
           

                <%: Html.LabelFor(model => model.T_R) %>
           
           

                <%: Html.TextBoxFor(model => model.T_R) %>
                <%: Html.ValidationMessageFor(model => model.T_R) %>
           
           
           

                <%: Html.LabelFor(model => model.AL_Year) %>
           
           

                <%: Html.TextBoxFor(model => model.AL_Year) %>
                <%: Html.ValidationMessageFor(model => model.AL_Year) %>
           
           
           

                <%: Html.LabelFor(model => model.School_Name) %>
           
           

                <%: Html.TextBoxFor(model => model.School_Name) %>
                <%: Html.ValidationMessageFor(model => model.School_Name) %>
           
           
           

                <%: Html.LabelFor(model => model.Guardian_Name) %>
           
           

                <%: Html.TextBoxFor(model => model.Guardian_Name) %>
                <%: Html.ValidationMessageFor(model => model.Guardian_Name) %>
           
           
           

                <%: Html.LabelFor(model => model.Guardian_TP) %>
           
           

                <%: Html.TextBoxFor(model => model.Guardian_TP) %>
                <%: Html.ValidationMessageFor(model => model.Guardian_TP) %>
           
           
           

                <%: Html.LabelFor(model => model.Guardian_Occupation) %>
           
           

                <%: Html.TextBoxFor(model => model.Guardian_Occupation) %>
                <%: Html.ValidationMessageFor(model => model.Guardian_Occupation) %>
           
           
           
               
           
       

    <% } %>

   

        <%: Html.ActionLink("Back to List", "Index") %>
   



Leave a Reply

Subscribe to Posts | Subscribe to Comments

Popular Post

Blogger templates

lakshika345@gmail.com. Powered by Blogger.

- Copyright © mp3s for you -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -