
Hi,
whenever you click on edit link, redirect it to [HttpPost] ActionMethod of that View.
ie., for the link button, write onclick="edit();"
Write javascript so that when you click on that link it goes to the post ActionMethod.
Javasctript :
function edit() {
document.addedit.submit()
}
@using (Html.BeginForm("PresentViewName", "ControllerName", FormMethod.Post, new { id = "addedit", name = "addedit" }))
{
// write the code
}
Write a stored procedure to insert the columns that you want.
//First create a table
create table editable
(
EmpID int primary key,
EmpName nvarchar(100),
Task nvarchar(500)
)
//Next create a stored procedure
create proc usp_editable
(
@EmpID int,
@EmpName nvarchar(100),
@Task nvarchar(500)
)
as
begin
insert into editable(EmpID, EmpName, Task) values(@EmpID, @EmpName, @Task)
end
Now, goto models folder, right click on it and select data tab and add entity data model.
select table editable from tables and usp_editable from storedProcedures and click on next.
After that goto to function Imports and select your stored proc.
Next, open your controller and write the Post ActionMethod.
[HttpPost]
public ActionResult PresentViewName(string EmpID, string EmpName, string Task etc....(include the parameters that you want from your view table))
{
// Put EmpID in TempData
TempData["EmpID"]=EmpID;
TempData.Keep();
db.usp_editable(EmpID, EmpName, Task);
db.SaveChanges();
return RedirectToAction("EditableView");
}
Now, retreive the column values from the table in this actionMethod
public ActionMethod Editable()
{
int EmpId = (string)TempData["EmpID"];
var query = from d in db.editable
where d.EmpID==EmpId
select new {
EmpID=d.EmpID,
EmpName=d.EmpName,
Task=d.Task
};
return View(query.ToList());
}
Declare the properties in the Modelclass Employee.
In this editable view, retreive the values.
<table>
<tr>
@foreach (ApplicationName.Models.Employee item in Model)
{
<td align="right" width="20%">
@Html.Label("Company Name :")
</td>
<td>
@Html.TextBox("EmpID", @item.EmpID)
</td>
</tr>
//repeat the code for EmpName and Task
</table>
Run the appliaction and you can see the values displayed in the text boxes.
You can message me for any quiries....
Regards,
Shree M.
Kavya Shree Mandapalli
ramuvalmiki07-22001, if this helps please login to Mark As Answer. | Alert Moderator