Is there a way to include two Get methods with different names but without any input parameters in a single controller in ASP.NET MVC 4 Web API?

For example, I want to have two GetBookXXX methods – one returning a list with only the book titles and the other returning a list with all book details (title, author, ISBN, etc). The approach I have seen so far is to use two separate controllers, but I would prefer to have a single one and not duplicating the plumbing code twice.

Thanks,

share|improve this question
Have you given it a try to see if it caused any issues? – CD Smith Jun 10 at 1:06
This looks like the answer your looking for: – Steve Aug 11 at 15:37
feedback

1 Answer

Yes, there is. Define your methods as follows:

[ActionName("GetBookXXX")]
public ActionResult BookTitles()
{
    return View();   
}

[ActionName("GetBookXXX")]
public ActionResult BookDetails(int id)
{
    return View();   
}

See http://haacked.com/archive/2008/08/29/how-a-method-becomes-an-action.aspx for further reference.

share|improve this answer
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.