Professional Documents
Culture Documents
Login Page Code
Login Page Code
@using TelerikMvcApplication4.Models; @{ ViewBag.Title = "Home Page"; } <h2>@ViewBag.Message</h2> @using (Html.BeginForm("SaveChanges","Home", FormMethod.Post)) { <label for="Name">Empid</label> <input type="text" id="empid" name="empid"/> <br /> <label for="fname">Fname</label> <input type="text" id="fname" name="fname" /><br /> <label for="mname">Mname</label> <input type="text" id="mname" name="mname"/><br /> <label for="lname">Lname</label> <input type="text" id="lname" name="lname"/><br /> <label for="address">Address</label> <input type="text" id="address" name="address"/><br /> <label for="Username">UserName</label> <input type="text" id="UserName" name="UserName"/><br />
@using (Html.BeginForm("Show_Result", "Home", FormMethod.Post)) { <input type="submit" value="Show Result" onclick="Show_Result()" /> }
<table id="nametable"> <tr> <th>Empid</th> <th>Fname</th> <th>Mname</th> <th>Lname</th> <th>Address</th> <th>UserName</th> <th>Password</th>
</tr> @{ if (ViewData["Data"] != null) { foreach (TelerikMvcApplication4.Models.Name n in (List<Name>)ViewData["Data"]) { <tr> <td>@n.Empid </td> <td>@n.Fname</td> <td>@n.Mname</td> <td>@n.Lname</td> <td>@n.Address</td> <td>@n.Username</td> <td>@n.Password</td> </tr>
} } }
</table> <script type="text/javascript"> function show_alert() { var empid = document.getElementById("empid").value; var fname = document.getElementById("fname").value; var mname = document.getElementById("mname").vaue; var lname = document.getElementById("lname").value; var address = document.getElementById("address").value; var username = document.getElementById("username").value; var password = document.getElementById("password").value; alert("Empid:" + empid + "Full Name:" + fname + mname + lname + "Address:"+address);
} </script>
Record.cshtml
@using TelerikMvcApplication4.Models; @{ Name name = new Name(); name = (Name)ViewData["searchedRecord"]; IEnumerable<Name> totalRecords = (IEnumerable<Name>)ViewData["totalRecords"];
@if (name != null) { <table> <tr> <th>Empid</th> <th>Fname</th> <th>Mname</th> <th>Lname</th> <th>Address</th> <th>UserName</th> <th>Password</th> </tr> <tr> <td>@name.Empid </td> <td>@name.Fname</td> <td>@name.Mname</td> <td>@name.Lname</td> <td>@name.Address</td> <td>@name.Username</td> <td>@name.Password</td> </tr> </table> } @using (Html.BeginForm("Delete", "Home", FormMethod.Post)) { <input id="empid" type="text" name="empID"/> <input type="submit" value="Delete" /> } <table id="nametable"> <tr> <th>Empid</th> <th>Fname</th> <th>Mname</th> <th>Lname</th> <th>Address</th> <th>UserName</th> <th>Password</th> </tr> @{ if (ViewData["totalRecords"] != null) { foreach (Name N in totalRecords) { <tr> <td>@N.Empid </td> <td>@N.Fname</td> <td>@N.Mname</td> <td>@N.Lname</td> <td>@N.Address</td> <td>@N.Username</td>
Controllerfile
using using using using using using System; System.Collections.Generic; System.Linq; System.Web; System.Web.Mvc; TelerikMvcApplication4.Models;
namespace TelerikMvcApplication4.Controllers { public class HomeController : Controller { NameEntities1 nameEntity = new NameEntities1(); public ActionResult Index() { return View(); } public ActionResult About() { return View(); }
public ActionResult SaveChanges(FormCollection collection) { Name name = new Name(); if (collection["Empid"] != null && collection["empid"] !="") { name.Empid = int.Parse(collection["empid"]); } name.Fname = (collection["fname"]); name.Mname = (collection["mname"]); name.Lname = (collection["lname"]); name.Address = (collection["address"]); nameEntity.Names.AddObject(name); name.Username = (collection["UserName"]);
public ActionResult Record(FormCollection collection) { Name name=new Name(); if (collection.Count > 0) { int empId = int.Parse(collection["empID"]); name = nameEntity.Names.FirstOrDefault(a => a.Empid== empId); ViewData["searchedRecord"]=name; nameEntity.SaveChanges(); } return View(); }
public ActionResult Delete(FormCollection collection) { Name name = new Name(); if (collection.Count > 0) { int Empid =int.Parse (collection["Empid"]); name = nameEntity.Names.FirstOrDefault(a => a.Empid==Empid); nameEntity.Names.DeleteObject(name); nameEntity.SaveChanges(); IEnumerable<Name> names = nameEntity.Names.ToList(); ViewData["totalRecords"] = names; } return View("Record"); } } }