How do you write a get method that retrieves the title of an object, not its Id - w/ ASP.NET MVC -


so method in repository use records db via id

    public blogstable getblogposts(int id)     {         return db.blogstables.singleordefault(d => d.id == id);     } 

and controller using method

    public actionresult details(int id)     {         blogstable blogpostdetails = repo.getblogposts(id);          return view(blogpostdetails);     } 

what need able write method allows me records db title, instead of id. have now

also, how set route use method? have now

            routes.maproute(             "default",                                                           "{controller}/{action}/{id}",                                        new { controller = "blog", action = "index", id = "" }           ); 

    public blogstable getblogpostsbytitle(string title)     {         return db.blogstables.singleordefault(d => d.title == title);     }      public actionresult details(string id)     {         blogstable blogpostdetails = repo.getblogpostsbytitle(id);          return view(blogpostdetails);     } 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -