mercredi 4 mai 2016

How can i overload Index in MVC

I've Index page which is included Blogs from database. Firstly, if i dont give the categoryID then all blogs must come to index page. If i give the category then i want to display blogs by categoryID so i need use Index overload.

public ActionResult Index(){List<Blog> blogs = db.Blogs.ToList();}
public ActionResult Index(int ID){List<Blog> blogs = db.Blogs.Where(x=>x.CategoryID==ID).ToList();}

But when i want to display all blogs the error come like this:

The current request for action 'Index' on controller type 'HomeController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index() on type SosyalSozluk.Areas.Blog.Controllers.HomeController System.Web.Mvc.ActionResult Index(Int32) on type SosyalSozluk.Areas.Blog.Controllers.HomeController

Aucun commentaire:

Enregistrer un commentaire