How to make edit to row from table using linq

0
down vote
favorite
In my Relation i have two tables relation (one to many)

table country

Id (primary key)

Countryname

table City

Id (primary key)

Cityname

Countryid (forign key)

I have controller City have list of data in city table as following

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LinqProject.Models;
namespace LinqProject.Controllers
{
public class CityController : Controller
{
mytaskdbEntities db = new mytaskdbEntities();

// GET: City
public ActionResult List()
{
return View(db.Cities.ToList());
}

and in view of List as following

<body>
<div>
<table>
@foreach (var item in Model)
{
<tr><td>@item.Cityname</td><td>@item.Country.Countryname</td></tr>
}
</table>
</div>
</body>

What i need actually adding EDIT button to view of list of city

and i can edit any cell of row city when click edit button and save it in

database

how to do edit record by using linq

the example show what i need as following

City country action

USA NEWYORK EDITBUTTON

USA WASHINTON EDITBUTTON

FRANCE PARIS EDITEBUTTON

when click EDIT button for row USA NEWYORK and change NEWYORK it to NEWGERSY it will edit

and records will be after edited as following

USA NEWGERSY EDITBUTTON

USA WASHINTON EDITBUTTON

FRANCE PARIS EDITEBUTTON

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.