TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Salman Mushtaq
NA
45
32.4k
Value embed with first field
Feb 6 2014 4:26 PM
Hi everyone , i make an application using Entity frame work (database first approach),
Whenever i click on link to update the data and insert new data the last field is embed with first field and itself is null, i cannot understand what the problem is that, sample code is given below
Action method Update:
public ActionResult Update(int id)
{
StudentEntities cx = new StudentEntities();
var q = cx.Infoes.Find(id);
return View(q);
}
View Update :
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Update</title>
</head>
<body>
<div>
<form action="/Home/update" method="Post">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="Name" value="@Model.Name" /></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" name="Age" value="@Model.Age" /></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="Address" value="@Model.Address" /></td>
</tr>
<tr>
<td>Interest</td>
<td><input type="text" name="Name" value="@Model.Interest" /></td>
</tr>
<tr>
<td><input type="submit" value="Update" /></td>
<td><a href="/Home/Index">Go back</a></td>
<td><input type="hidden" name="Id" value="@Model.Id" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Method update:
[HttpPost]
public ActionResult update()
{
int Id = int.Parse(Request["ID"]);
string Name = Request["Name"];
int Age = int.Parse(Request["Age"]);
string Address = Request["Address"];
string Interest = Request["Interest"];
StudentEntities cx = new StudentEntities();
var q = cx.Infoes.Find(Id);
q.Name = Name;
q.Age = Age;
q.Address = Address;
q.Interest = Interest;
cx.SaveChanges();
var l = cx.Infoes.ToList();
return View("Index", l);
}
Reply
Answers (
0
)
why is the error " use of unassigned local variable" ?
code with design for Reminder application