Monday, April 16, 2012

How can I get LINQ to accept my argument?

I want to make "Create" option in ASP.NET MVC 3 in C#.
I am working with entity framework.



I want to make a method in one of my models that could insert all the data I posted into my action.



my model looks like this :



public class person { 
public int id { get; set; }
public string name{ get; set; }
public string carBrand { get; set; }
public string streetname{ get; set; }
}


My view is strongly typed with this class above, making a "Create" page. So it creates the textboxes automatically for me.



The object Person, I gave my Controller has a parameter.



public ActionResult Index(person objectPerson)
{
//invoke method here
}


Then I wanted my method, which came from the model, to take this object and add its properties to my database... but the problem is, it doesn't work the way I thought it would.



public void createPerson(person objectPerson)
{
db.MyTable.AddObject(objectPerson)
}


giving the following error : the best overloaded method match has some invalid arguments





No comments:

Post a Comment