Archive for 2015
My Model Popup
html
div class="row">
div id="popupChangeMarks" class="modal">
!-- dialog contents -->
div class="modal-body">
div class="col-md-4">
div style="margin-bottom: 5px" class="input-group">
span class="input-group-addon">Student ID
div id="popupChangeMarks" class="modal">
!-- dialog contents -->
div class="modal-body">
div class="col-md-4">
div style="margin-bottom: 5px" class="input-group">
span class="input-group-addon">Student ID
div>
div>
JQuery Popup
function LoadChangeMarksPopup() {
dialog = $("#popupChangeMarks").dialog({
autoOpen: true,
title: "Change Marks",
width: 800,
modal: true,
closeOnEscape: false,
open: function (event, ui) { $(".ui-dialog-titlebar-close", ui.dialog || ui).hide(); },
buttons: {
Save: function () {
//arrr['wt'] = $("#drpWithdrawalType").val();
UpdateMarks();
dialog.dialog("close");
LoadMarksByFetchStudentsToGrid();
},
Cancel: function () {
dialog.dialog("close");
$("#txtMarks").val("");
}
},
close: function () {
}
});
dialog.dialog("open");
}
--------------------------------------------
function LoadChangeMarksDetails()
{
var theGrid = $('#tblMarks'), rowID = theGrid.jqGrid('getGridParam', 'selrow'), value = theGrid.jqGrid('getCell', rowID, 'Student_M_ID');
$("#txtStudentID").val(value);
var theGrid = $('#tblMarks'), rowID = theGrid.jqGrid('getGridParam', 'selrow'), value = theGrid.jqGrid('getCell', rowID, 'Test_M_ID');
$("#txtTestID").val(value);
var theGrid = $('#tblMarks'), rowID = theGrid.jqGrid('getGridParam', 'selrow'), value = theGrid.jqGrid('getCell', rowID, 'Mark');
$("#txtMarks").val(value);
}
function initGrid() {
jQuery("#tblMarks").jqGrid({
datatype: "json",
colNames: [ 'Student ID', 'Name', 'Marks', 'Test ID'],
colModel: [
//{ name: 'School', index: 'School', align: "center", hidden: false, editable: false },
{ name: 'Student_M_ID', index: 'Student_M_ID', align: "center", hidden: false, editable: false },
{ name: 'Name', index: 'Name', align: "center", hidden: false, editable: false },
{ name: 'Mark', index: 'Mark', align: "center", hidden: false, editable: true },
{ name: 'Test_M_ID', index: 'Test_M_ID', align: "center", hidden: true, editable: true },
],
pgbuttons: true,
rowList: [],
pgtext: null,
pager: jQuery('#tblMarks-Pager'),
viewrecords: true,
sortorder: "asc",
autowidth: true,
height: "100%",
hiddengrid: false,
caption: "Student Marks",
cellEdit: false,
shrinkToFit: true,
cellsubmit: 'clientArray',
onSelectRow: function () {
// retrieveFmssFirstInspectionDetails();
//$("#ques").show();
// $("#tb").addClass("tab-pane");
},
ondblClickRow: function () {
// alert(value);
LoadChangeMarksPopup();
LoadChangeMarksDetails();
}
});
}
--------------------------------------------
function LoadChangeMarksDetails()
{
var theGrid = $('#tblMarks'), rowID = theGrid.jqGrid('getGridParam', 'selrow'), value = theGrid.jqGrid('getCell', rowID, 'Student_M_ID');
$("#txtStudentID").val(value);
var theGrid = $('#tblMarks'), rowID = theGrid.jqGrid('getGridParam', 'selrow'), value = theGrid.jqGrid('getCell', rowID, 'Test_M_ID');
$("#txtTestID").val(value);
var theGrid = $('#tblMarks'), rowID = theGrid.jqGrid('getGridParam', 'selrow'), value = theGrid.jqGrid('getCell', rowID, 'Mark');
$("#txtMarks").val(value);
}
function initGrid() {
jQuery("#tblMarks").jqGrid({
datatype: "json",
colNames: [ 'Student ID', 'Name', 'Marks', 'Test ID'],
colModel: [
//{ name: 'School', index: 'School', align: "center", hidden: false, editable: false },
{ name: 'Student_M_ID', index: 'Student_M_ID', align: "center", hidden: false, editable: false },
{ name: 'Name', index: 'Name', align: "center", hidden: false, editable: false },
{ name: 'Mark', index: 'Mark', align: "center", hidden: false, editable: true },
{ name: 'Test_M_ID', index: 'Test_M_ID', align: "center", hidden: true, editable: true },
],
pgbuttons: true,
rowList: [],
pgtext: null,
pager: jQuery('#tblMarks-Pager'),
viewrecords: true,
sortorder: "asc",
autowidth: true,
height: "100%",
hiddengrid: false,
caption: "Student Marks",
cellEdit: false,
shrinkToFit: true,
cellsubmit: 'clientArray',
onSelectRow: function () {
// retrieveFmssFirstInspectionDetails();
//$("#ques").show();
// $("#tb").addClass("tab-pane");
},
ondblClickRow: function () {
// alert(value);
LoadChangeMarksPopup();
LoadChangeMarksDetails();
}
});
}
JQ Grid Intializing Resources
Download Jquery.JqGrid using NuGet. Then add these Links
-----------------------------------------------------------------------
URL-
http://www.c-sharpcorner.com/UploadFile/97fc7a/integration-of-jqgrid-with-mvc4-application-part-1/
Index Page Html/Bootstrap
div class="container" style="z-index:0">
h1 id="hd-event-title">Event Details
hr>
form role="form">
div class="row">
div class="col-md-8">
div class="form-group">
label for="code">Title
input type="text" id="txt-event-title" class="form-control input-lg" required">
span id="spn-title-error" class="help-block">Please correct the error
div>
div>
h1 id="hd-event-title">Event Details
hr>
form role="form">
div class="row">
div class="col-md-8">
div class="form-group">
label for="code">Title
input type="text" id="txt-event-title" class="form-control input-lg" required">
span id="spn-title-error" class="help-block">Please correct the error
div>
div>
Posted by sinhalamp3
Bootstrap Import - Compulsory
BundleConfig.cs
bundles.Add(new ScriptBundle("~/Scripts/bootstrap").Include(
"~/Scripts/bootstrap.js")
);
bundles.Add(new ScriptBundle("~/Scripts/knockoutjs").Include(
"~/Scripts/knockout-{version}.js",
"~/Scripts/knockout.mapping.min.js",
"~/Scripts/ko.observableDictionary.js",
"~/Scripts/knockout-jqAutocomplete.js"
)
);
bundles.Add(new ScriptBundle("~/Scripts/jqueryui").Include(
"~/Content/jquery-ui-1.11.4/jquery-ui.js")
);
bundles.Add(new ScriptBundle("~/Scripts/jqueryval").Include(
"~/Scripts/jquery.validate*")
);
bundles.Add(new StyleBundle("~/Styles/bootstrap").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-theme.css")
);
bundles.Add(new StyleBundle("~/Styles/font-awesome").Include(
"~/Content/font-awesome.css"
)
);
bundles.Add(new StyleBundle("~/Styles/jqueryui").Include(
"~/Content/jquery-ui-1.11.4/jquery-ui.css",
"~/Content/jquery-ui-1.11.4/jquery-ui.theme.css"
)
);
/////////////////////////////////////////////// FULL Bundle Config ...-----------------------
bundles.IgnoreList.Clear();
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/bootstrapjs").Include(
"~/Scripts/bootstrap.min.js"));
bundles.Add(new StyleBundle("~/Content/bootstrapcss").Include(
"~/Content/bootstrap.min.css",
"~/Content/bootstrap-responsive.min.css"));
//------------------------------------------------
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at http://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
//-------------------------------------------------------------------------
bundles.Add(new ScriptBundle("~/Scripts/bootstrap").Include(
"~/Scripts/bootstrap.js")
);
bundles.Add(new ScriptBundle("~/Scripts/knockoutjs").Include(
"~/Scripts/knockout-{version}.js",
"~/Scripts/knockout.mapping.min.js",
"~/Scripts/ko.observableDictionary.js",
"~/Scripts/knockout-jqAutocomplete.js"
)
);
bundles.Add(new ScriptBundle("~/Scripts/jqueryui").Include(
"~/Content/jquery-ui-1.11.4/jquery-ui.js")
);
bundles.Add(new ScriptBundle("~/Scripts/jqueryval").Include(
"~/Scripts/jquery.validate*")
);
bundles.Add(new StyleBundle("~/Styles/bootstrap").Include(
"~/Content/bootstrap.css",
"~/Content/bootstrap-theme.css")
);
bundles.Add(new StyleBundle("~/Styles/font-awesome").Include(
"~/Content/font-awesome.css"
)
);
bundles.Add(new StyleBundle("~/Styles/jqueryui").Include(
"~/Content/jquery-ui-1.11.4/jquery-ui.css",
"~/Content/jquery-ui-1.11.4/jquery-ui.theme.css"
)
);
------------------------------------------- Layout Page Import JQuery and Others -----------
@* @System.Web.Optimization.Scripts.Render("~/Scripts/jquery-1.9.1")*@
@System.Web.Optimization.Scripts.Render("~/Scripts/jqueryui")
@* @System.Web.Optimization.Scripts.Render("~/Scripts/jquery")*@
@* @System.Web.Optimization.Scripts.Render("~/Scripts/bootstrap")*@
@System.Web.Optimization.Styles.Render("~/Styles/jqueryui")
@System.Web.Optimization.Styles.Render("~/Styles/bootstrap")
@System.Web.Optimization.Styles.Render("~/Styles/font-awesome")
@System.Web.Optimization.Scripts.Render("~/Scripts/knockoutjs")
MVC with Ajax and InitJQGrid
Save Functions( Ajax)
function SaveEventDetails() {var startDate = $("#txt-event-start-date").val();
var startTime = $("#txt-event-start-time").val();
var endDate = $("#txt-event-end-date").val();
var endTime = $("#txt-event-end-time").val();
//alert(startDate); alert(startTime); alert(endDate); alert(endTime);
if ($("#txt-event-title").val() != "") {
var title = $("#txt-event-title").val();
var description = $("#txt-event-description").val();
var startTime = startDate + " " + startTime;
var endTime = endDate + " " + endTime;
var location = $("#txt-event-location").val();
//var event_ = {
// EventTitle: title, Description: description, StartDateTime: '', EndDateTime: '', Location: location
//};
var event_ = {};
event_["EventTitle"] = title;
event_["Description"] = description;
event_["StartDateTime"] = startTime;
event_["EndDateTime"] = endTime;
event_["Location"] = location;
$.ajax({
type: "POST", // Type
data: JSON.stringify({ 'event_': event_, 'arrTickets': arrTickets }),
dataType: 'json',
url: "Event/AddEvent",
async: false,
contentType: "application/json",
success: function (msg) {
$("#txt-event-title").val() = "";
$("#txt-event-description").val() = "";
$("#txt-event-location").val() = "";
LoadEventsToGrid();
}
});
}
else {
$("#spn-title-error").html('Enter the Title');
$("#spn-title-error").parent().removeClass("form-group has-success");
$("#spn-title-error").parent().addClass("form-group has-error");
}
//bootbox.dialog({
// message: "Invoice saved successfully",
// title: "SM Information",
// buttons: {
// danger: {
// label: "OK",
// className: "btn-success",
// callback: function () {
// }
// }
// }
//});
//$("#txt-event-title").val() = "aa";
//$("#txt-event-description").val() = "aa";
//$("#txt-event-location").val() = "";
//$("#spn-save-msg").html('Event Saved Successfully !');
//$("#spn-save-msg").parent().addClass("form-group has-success");
//$("#spn-save-msg").parent().removeClass("form-group has-error");
//alert("Success !");
}
----------------------------------------------------------------------------------
JQGrid Initializer
function InitializeGrid (){
$("#tbl-evnts").jqGrid({
datatype: "json",
colNames: ["Event ID", "Event Title", "Description", "StartDateTime", "EndDateTime","Location"],
colModel: [
{ name: "EventID", index: "EventID", hidden: true },
{ name: "EventTitle", index: "EventTitle" },
{ name: "Description", index: "Description" },
{ name: 'StartDateTime', index: 'StartDateTime', editable: false, formatter: 'datetime'},
{ name: 'EndDateTime', index: 'EndDateTime', editable: false },
{ name: 'Location', index: 'Location', editable: false }
],
rowNum: 25,
rowList: [5, 10, 20],
viewrecords: true,
sortorder: "asc",
autowidth: true,
height: "100%",
width: "100%",
hiddengrid: false,
//cellEdit: true,
cellsubmit: 'clientArray',
// multiselect: true,
// shrinkToFit: false,
caption: "Event Details",
onSelectRow: function (rowid, status) {
}
//
});
LoadEventsToGrid();
}
function LoadEventsToGrid() {
var grid = $("#tbl-evnts");
grid.clearGridData();
// var dataObject = JSON.stringify({ 'location_id': location_id });
$.ajax({
// data: dataObject,
url: 'Event/ViewEvents',
type: 'post',
contentType: 'application/json',
success: function (inputParam) {
// $("#student-grid-array").removeAll();
for (var i = 0; i < inputParam.length; i++) {
grid.addRowData(i, inputParam[i]);
}
}
});
}
---------------------------------------
function DeleteFormatter(cellvalue, options, rowObject) {
//alert(cellvalue);
DeleteTicket = function (id)
{
//alert(id);
arrTickets.splice(0,1);
AddTicketsToGrid();
}
// var img = '
';var img = '
';//alert(rowObject['ID']);
return img;
}
Object to Json
Convert to Json
protected void Button1_Click(object sender, EventArgs e){
Student s1 = new Student();
s1.StudentID = TextBox1.Text;
s1.Fname = TextBox2.Text;
s1.Lname = TextBox3.Text;
var json = new JavaScriptSerializer().Serialize(s1);
// Write the string to a file.
System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Users\Lakshika\Desktop\dd.txt");
file.WriteLine(json);
List
student.Add(s1);
_studentOp = new StudentOperations();
_studentOp.SaveStudent(student);
file.Close();
}
MVC 3 Full Teacher
Teacher Controller
public ActionResult Index(){
return View();
}
public ActionResult Create()
{
DBOperations db = new DBOperations();
List
ViewBag.QualificationList = new SelectList(qualification, "QualificationID", "QualificationType");
List
ViewBag.SchoolList = new SelectList(school, "SchoolID", "SchoolName");
return View();
}
[HttpPost]
public ActionResult Create(Teacher teacher)
{
DBOperations db = new DBOperations();
List
ViewBag.QualificationList = new SelectList(qualification, "QualificationID", "QualificationType");
List
ViewBag.SchoolList = new SelectList(school, "SchoolID", "SchoolName");
db.insertTeacher(teacher);
return View();
}
public ActionResult ViewTeacher()
{
DBOperations db = new DBOperations();
List
return View(teachers.AsEnumerable());
}
//public JsonResult View(int id)
//{
// DBOperations db = new DBOperations();
// return Json(db.getTeacherById(id), JsonRequestBehavior.AllowGet);
//}
public ActionResult ViewTeacherById(int id)
{
DBOperations db = new DBOperations();
Teacher teacher = db.getTeacherById(id);
List
foreach (var items in school)
{
if (items.SchoolID == teacher.SchoolID)
{
ViewData["SchoolName"] = items.SchoolName;
}
}
List
foreach (var items in qualifications)
{
if (items.QualificationID == teacher.QualificationID)
{
ViewData["Type"] = items.QualificationType;
}
}
return View(teacher);
}
public ActionResult UpdateTeacher(int id)
{
DBOperations db = new DBOperations();
List
ViewBag.SchoolList = new SelectList(schools, "SchoolID", "SchoolName");
List
ViewBag.QualificationList = new SelectList(qualifications, "QualificationID", "QualificationType");
Teacher model = db.getTeacherById(id);
return View(model);
}
[HttpPost]
public ActionResult UpdateTeacher(Teacher teacher)
{
DBOperations db = new DBOperations();
List
ViewBag.SchoolList = new SelectList(schools, "SchoolID", "SchoolName");
List
ViewBag.QualificationList = new SelectList(qualifications, "QualificationID", "QualificationType");
// Teacher model = db.getTeacherById(id);
db.UpdateTeacher(teacher);
return View("ViewTeacher");
}
[HttpDelete]
public ActionResult ViewTeacher(int id)
{
DBOperations db = new DBOperations();
db.DeleteTeacher(id);
return View("ViewTeacher");
}
-------------------------------------------------------------------------------------
DB Operations Class
public void insertTeacher(Teacher teacher)
{
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into Teacher values ('"+teacher.TeacherName+"','"+teacher.TeacherNIC+"','"+teacher.TeacherAddress+"',"+teacher.QualificationID+","+teacher.SchoolID+")";
cmd.ExecuteNonQuery();
conn.Close();
}
public List getAllQualifications()
{
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from Qualification";
SqlDataReader dr = cmd.ExecuteReader();
List qualifications = new List();
while (dr.Read())
{
Qualification qualification = new Qualification();
qualification.QualificationID = dr.GetInt32(0);
qualification.QualificationType = dr.GetString(1);
qualifications.Add(qualification);
}
return qualifications;
}
public List getAllSchools()
{
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from School";
SqlDataReader dr = cmd.ExecuteReader();
List schools = new List();
while (dr.Read())
{
School school = new School();
school.SchoolID = dr.GetInt32(0);
school.SchoolName = dr.GetString(1);
schools.Add(school);
}
return schools;
}
public List getAllTeachers()
{
List teachers = new List();
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM Teacher";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Teacher teacher = new Teacher();
teacher.TeacherID = dr.GetInt32(0);
teacher.TeacherName = dr.GetString(1);
teacher.TeacherNIC = dr.GetString(2);
teacher.TeacherAddress = dr.GetString(3);
teacher.QualificationID = dr.GetInt32(4);
teacher.SchoolID = dr.GetInt32(5);
teachers.Add(teacher);
}
return teachers;
}
public Teacher getTeacherById(int teacher_id)
{
Teacher teacher = new Teacher();
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "select * from Teacher where TeacherID="+teacher_id+"";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
teacher.TeacherID = dr.GetInt32(0);
teacher.TeacherName = dr.GetString(1);
teacher.TeacherNIC = dr.GetString(2);
teacher.TeacherAddress = dr.GetString(3);
teacher.QualificationID = dr.GetInt32(4);
teacher.SchoolID = dr.GetInt32(5);
}
return teacher;
}
public void UpdateTeacher(Teacher teacher)
{
int teacher_id = teacher.TeacherID;
string teacher_name = teacher.TeacherName;
string teacher_address = teacher.TeacherAddress;
string teacher_nic = teacher.TeacherNIC;
int quali_id = teacher.QualificationID;
int school_id = teacher.SchoolID;
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Update Teacher set TeacherName='" + teacher_name + "',TeacherNIC='" + teacher_nic + "',TeacherAddress='" + teacher_address + "',QualificationID=" + quali_id + ",SchoolID=" + school_id + " where TeacherID=" + teacher_id + "";
cmd.ExecuteNonQuery();
conn.Close();
}
public void DeleteTeacher(int id)
{
SqlConnection conn = new SqlConnection(Connection.ConnectionString);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "delete from Teacher where TeacherID="+id+"";
cmd.ExecuteNonQuery();
conn.Close();
}
---------------------------------------------------------------------------------------------
DBConnection Class
public class Connection{
public static string ConnectionString
{
get { return "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SINGADB;Data Source=Lakshika-PC\\SQLEXPRESS"; }
}
}
MVC 2 Create, Search
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
<% using (Html.BeginForm()) {%>
<%: Html.ValidationSummary(true) %>
<%: 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") %>
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
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) %>
<%: 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") %>