12
Answers

MVC

Harpreet

Harpreet

9y
470
1
Hi Sir,
Can u plzz check this one..
i am sending my whole code can u plz check its urgent.. in post method plz check i m not getting that update query
View:
@using MyDemoProject.Models
@model DetailsList
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Id)
</td>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.OldSeq)
</td>
<td>
<input type="text" value="@item.NewSeq" />
</td>
<td>
<input type="submit" value="Update" id="btnUpdate" />
</td>
</tr>
}
model
public class EmpDetails
{
public int Id { get; set; }
public string Name { get; set; }
public int OldSeq { get; set; }
public int NewSeq { get; set; }
}
public class DetailsList
{
public int Id { get; set; }
public string Name { get; set; }
public int OldSeq { get; set; }
public int NewSeq { get; set; }
public IEnumerable<EmpDetails> EmpDetailsList { get; set; }
}
Controller
projectEntities obj = new projectEntities();
[HttpGet]
public ActionResult EmployeeDetails()
{
List<EmpDetails> c2 = new List<EmpDetails>();
EmpDetails model = new EmpDetails();
var Empdet = from x in obj.Employees
//where x.Id==model.Id
select x;
foreach(var item in Empdet)
{
model = new EmpDetails();
model.Id = item.Id;
model.Name = item.Name;
model.OldSeq = Convert.ToInt16(item.OldSeq);
model.NewSeq = Convert.ToInt16(item.NewSeq);
c2.Add(model);
}
DetailsList abc = new DetailsList();
abc.EmpDetailsList = c2;
return View(c2);
}
[HttpPost]
public ActionResult EmployeeDetails(DetailsList model)
{
List<EmpDetails> results =
(from p in obj.Employees
where p.Id == model.Id
select p).ToList();
foreach (EmpDetails p in results)
{
p.is_default = false;
}
obj.SaveChanges();
return View();
}
}

Answers (12)