Have created a mvc application in tat for the create new link i have created a controller and view..but m not able ti render the view in the controller.The savechanges is not coming in drop down..How to proceed.Any help
COntroller code
public ActionResult CreateNew(studentDetail student)
{
dc.studentDetails.Add(student);
dc.SaveChanges();
return View(student);
}
m not getting the .Add and .SaveChanges dropdown..
System.Data.Linq.Table<MvcApplication2.studentDetail>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table<MvcApplication2.studentDetail>' could be found (are you missing a using
directive or an assembly reference?)
Priya R
Member
55 Points
51 Posts
MVC Create new page
May 03, 2012 09:15 AM|LINK
Have created a mvc application in tat for the create new link i have created a controller and view..but m not able ti render the view in the controller.The savechanges is not coming in drop down..How to proceed.Any help
COntroller code
public ActionResult CreateNew(studentDetail student)
{
dc.studentDetails.Add(student);
dc.SaveChanges();
return View(student);
}
m not getting the .Add and .SaveChanges dropdown..
ignatandrei
All-Star
137698 Points
22155 Posts
Moderator
MVP
Re: MVC Create new page
May 03, 2012 10:03 AM|LINK
What dropdown?
Did your code compiles?
Who is dc ?
Priya R
Member
55 Points
51 Posts
Re: MVC Create new page
May 03, 2012 10:36 AM|LINK
dc is the object name of the model class used to retrieve the database...
not exactly dropdown i meant to say m not getting the savechanges function and also add method( which s inbuilt). It says the function does not exist
code s compiled..but on click of the link i m not getting the page.
christiandev
Star
8607 Points
1841 Posts
Re: MVC Create new page
May 03, 2012 11:02 AM|LINK
is the createNew being called when debugging? you seem to be missing [AcceptVerbs(HttpVerbs.Post)]
Regards, Christiandev (@chrisdev80), MCPD Web (2 & 4) & MCTS Windows (www.ScoreDonkey.com)
Priya R
Member
55 Points
51 Posts
Re: MVC Create new page
May 03, 2012 11:10 AM|LINK
no..code is not cmpiled and createnew is not called.. tried with [AcceptVerbs(HttpVerbs.Post)]..still no luck.
the prob s with savechanges and add method does not exist..
How to get those functions?
Should i use any namespace to get the reference?
ignatandrei
All-Star
137698 Points
22155 Posts
Moderator
MVP
Re: MVC Create new page
May 03, 2012 11:59 AM|LINK
Please tell compiler error.
Priya R
Member
55 Points
51 Posts
Re: MVC Create new page
May 03, 2012 12:07 PM|LINK
Error message is
System.Data.Linq.Table<MvcApplication2.studentDetail>' does not contain a definition for 'Add' and no extension method 'Add' accepting a first argument of type 'System.Data.Linq.Table<MvcApplication2.studentDetail>' could be found (are you missing a using directive or an assembly reference?)
and the same error for savechanges too
ignatandrei
All-Star
137698 Points
22155 Posts
Moderator
MVP
Re: MVC Create new page
May 04, 2012 03:55 AM|LINK
Maybe it is true. How did you generate the dc ? I think that you are using L2S with EF methods.
Priya R
Member
55 Points
51 Posts
Re: MVC Create new page
May 04, 2012 07:05 AM|LINK
yes i m using L2S
dc is created as
private MusicClassesDataContext dc = new MusicClassesDataContext();
where MusicClassesDataContext is the model.
If not wat s the correct method must be used
ignatandrei
All-Star
137698 Points
22155 Posts
Moderator
MVP
Re: MVC Create new page
May 04, 2012 07:11 AM|LINK
The method is
dc.SubmitChanges();
as stated at
http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext_methods.aspx
not
You have to look to a L2S tutorial - such as links from
http://msdn.microsoft.com/en-us/library/bb358844.aspx
(see Topic / Location)