asp.net mvc - Does not contain a definition for 'AddToPosts' and no extension method -


i still learning asp.net/mvc , following along tutorial matt blagden (you tube) on building blog..

after making post controller getting error in snippet of code handles adding tag post if new post. thought method addtoposts should have been generated when added new entity data model.

the error is:

blog.models.blogmodel not contain definition 'addtoposts' , no extension method 'addtoposts'. postscontroller.cs accepting first argument of type 'blog.models.blogmodel' found (are missing using directive or assembly reference?)

the portion of code giving me error is:

            if (!id.hasvalue)         {             model.addtoposts(post);          } 

here entire post controller

using system; using system.collections.generic; using system.linq; using system.web; using system.web.mvc; using blog.models; using system.data.entitymodel; using system.text;  namespace blog.controllers { public class postscontroller : controller {     // access model     private blogmodel model = new blogmodel();      public actionresult index()     {         return view();     }      // way input sample data database     [validateinput(false)]     public actionresult update(int? id, string title, string body, etc.....)     {         //if not admin redirect index          if (!isadmin)         {             return redirecttoaction("index");         }          // post         post post = getpost(id);         // populate simple properties          post.title = title;         post.body = body;         post.datetime = datetime;         post.tags.clear();  // first clear tag list          //ensure input sequence of tag names not null         tags = tags ?? string.empty;          //split sequence list of tag names         string[] tagnames = tags.split(new char[] { ' ' }, etc...          //get or create each tag named         foreach (string tagname in tagnames)         {             //add tag             post.tags.add(gettag(tagname));          }          if (!id.hasvalue)         {             model.addtoposts(post);          }          model.savechanges();         return redirecttoaction("details", new { id = post.id });     }       // prompts user input data database     public actionresult edit(int? id)     {         post post = getpost(id);          //accumulates list of current tagnames         stringbuilder taglist = new stringbuilder();          foreach (tag tag in post.tags)         {             //append each tagname             taglist.appendformat("{0} ", tag.name);         }         //gives taglist view         viewbag.tags = taglist.tostring();          return view(post);      }       private tag gettag(string tagname)     {   // if tag set tag, if not create new 1 (just getpost)         return model.tags.where(x => x.name == tagname).firstordefault() ?? etc....      }        private post getpost(int? id)     {         // if id set post, if not make new one..         return id.hasvalue ? model.posts.where(x => x.id == id).first() : etc.....       // todo: don't return true      public bool isadmin     /* reads session state */     {         { return true; /*{ return session["isadmin"] != null && etc...     } } 

}

if "addtoposts" coming static class, try adding using statement of namespace add post class exists.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -