0% found this document useful (0 votes)
2 views

Lab3.3 Database First Approach-First Starting Web MVC

dotnet labreport

Uploaded by

karantestingdemo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab3.3 Database First Approach-First Starting Web MVC

dotnet labreport

Uploaded by

karantestingdemo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

https://www.youtube.com/watch?

v=zvMOHUNwO0o

development kits through installer

Step1: Create Asp.net Web Application and choose


Asp.Net Web Application (.Net Framework)

choose the folder structure


Step2: Choose MVC project Structure
Build and RUn the project

Step3: Create database file and connect using


server explorer and add ado.net dataset into the
project. By clicking the right click in the project in
solution explorer.
After selecting ADO Net put sql server name and it
will load the data base and list down the list
Build the project and inorder to add the other table
or update database go to the .edmx file in the model and right
click the UI and choose update database from there . After that build
the project and class file can be seen in the
models.

Step4: Add Controller File by clicking right click in


controller and add controller with entity framework
read write method
After controller is created, controller details and
view folder can be seen respectively .

Controller Class code :

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using WebApplication2;

namespace WebApplication2.Controllers
{
public class StudentDetailsController : Controller
{
private ScholEntities db = new ScholEntities();

// GET: StudentDetails
public ActionResult Index()
{
return View(db.StudentDetails.ToList());
}
// GET: StudentDetails/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StudentDetail studentDetail = db.StudentDetails.Find(id);
if (studentDetail == null)
{
return HttpNotFound();
}
return View(studentDetail);
}

// GET: StudentDetails/Create
public ActionResult Create()
{
return View();
}

// POST: StudentDetails/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include =
"Id,Name,ParentsName,MobileNumber,Status,Remarks")] StudentDetail studentDetail)
{
if (ModelState.IsValid)
{
db.StudentDetails.Add(studentDetail);
db.SaveChanges();
return RedirectToAction("Index");
}

return View(studentDetail);
}

// GET: StudentDetails/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StudentDetail studentDetail = db.StudentDetails.Find(id);
if (studentDetail == null)
{
return HttpNotFound();
}
return View(studentDetail);
}

// POST: StudentDetails/Edit/5
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details see https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include =
"Id,Name,ParentsName,MobileNumber,Status,Remarks")] StudentDetail studentDetail)
{
if (ModelState.IsValid)
{
db.Entry(studentDetail).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(studentDetail);
}

// GET: StudentDetails/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
StudentDetail studentDetail = db.StudentDetails.Find(id);
if (studentDetail == null)
{
return HttpNotFound();
}
return View(studentDetail);
}

// POST: StudentDetails/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
StudentDetail studentDetail = db.StudentDetails.Find(id);
db.StudentDetails.Remove(studentDetail);
db.SaveChanges();
return RedirectToAction("Index");
}

protected override void Dispose(bool disposing)


{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
SQL

USE [Schol]
GO

/****** Object: Table [dbo].[StudentDetails] Script Date: 11/15/2022 2:51:52


PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[StudentDetails](


[Id] [int] NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[ParentsName] [nvarchar](50) NOT NULL,
[MobileNumber] [nvarchar](50) NOT NULL,
[Status] [bit] NOT NULL,
[Remarks] [nvarchar](50) NULL,
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF)
ON [PRIMARY]
) ON [PRIMARY]
GO

You might also like