Reputation: 2439
I want to retrieve some files using the contact id
here's my code.
public string Edit(int id)
{
var GetContacts = from c in db.Contacts where c.ContactID == id
select c;
return GetContacts.ToString();
}
when I go to contacts/edit/1
for example. it displays this.
System.Data.Objects.ObjectQuery`1[ContactsMVC.Models.Contact]
what is wrong with my code? is it in the query. I actually want to get the name
, mobile
, and email
of the user.
I am new to asp.net C# mvc 2 so bear with me.
thanks in advance.
Upvotes: 0
Views: 44
Reputation: 1526
Change your return type
public IEnumerable<Contacts> Edit(int id)
{
var GetContacts = from c in db.Contacts where c.ContactID == id
select c;
return GetContacts.ToList();
}
OR you can return as Json Object
public ActionResult Edit(int id)
{
var GetContacts = from c in db.Contacts where c.ContactID == id
select c;
return Json(GetContacts.ToList(), JsonRequestBehavior.AllowGet);
}
Client Side - (for json one):
$.get("yourController/Edit",{id:yourid}, function(data){
alert(data.Name); // For example
})
Upvotes: 1