.


:




:

































 

 

 

 


ASP.NETMVC 5, . NetFramework 4.6

 

 

1. MVC 5 ASP. NET VisualStudio 2015

MVC.

->. . Web , Asp.NET (ASP.NETEmptyWebApplication). . .

 

, MVC , .

 

 

.

New Item.

.

.

.

id. IdentitySpecification IsIdentity Yes. id 1. Identityincrement . 0.

(Name) (Post).

Primarykey i d.

.

SolutionExplorer, .

ADO.NET Entity Data Model. NamesModel.

. .

. VisualStudio . , MS SQL Server, ADO.NET. , , , .

DataBase1.mdf. NamesDBEntities.

, , . Table1. Namespace ( ). , Models.

.

.

MVC . . NameController.

, Table!

.

SolutionExplorer .

. .

.

.

. ( BuildSolution), Models, .

. .

Models Table1 () . Create Create.

Index list.

?

~/Views/Shared/_Layout.cshtml

. , .

, , Create ( ). . . , [HttpPost]. , .

reate, , .

using

( HttpStatusCode)?

using System.Net;

Table1. db:

, . :

:

, Table1, NameToSave.

index list;

index:

Details: details; :

Edit: Edit; .

publicActionResult Edit(int id)

{

return View(db.Table.FirstOrDefault(P =>P.Id == id));

}

Edit, :

[HttpPost]

publicActionResult Edit(Table table)

{

 

if (ModelState.IsValid)

{

db.Entry(table).State = EntityState.Modified;

db.SaveChanges();

returnRedirectToAction("Index");

}

returnView(table);

 

}

, Delete. Delete .

publicActionResult Delete(int id)

{

return View(db.Table.Single(P =>P.Id == id));

}

 

, :

 

( MVC2, DeleteObject Remove):

publicActionResult Delete(int id, Table name)

{

try

{

db.Table.Remove(db.Table.Single(P =>P.Id == id));

db.SaveChanges();

returnRedirectToAction("Index");

}

catch

{

returnView();

}

}

index. _Layout.cshtml:

:

:

MynameController , , Index , Name .

BuildSolution . , :

:

:

:

 



<== | ==>
ASP.NETMVC | .
:


: 2018-10-15; !; : 174 |


:

:

, .
==> ...

1487 - | 1397 -


© 2015-2024 lektsii.org - -

: 0.025 .