Reputation: 16239
I'm working on mvc4 web api
project.
I have created a new controller GroupValuesController
and i have following methods
public GroupViewModel Get()
public List<GroupModel> Get(Guid Id)
public List<GroupModel> GetDetails(Guid Id)
First two methods are working fine I'm calling them from a group.cshtml view
like following
$.getJSON(
"api/groupvalues",
function (data) {
and
$.getJSON(
"api/groupvalues/" + id,
function (data) {
For third controller method public List<GroupModel> GetDetails(Guid Id)
i'm executing that from Details.cshtml view
like following but it is not working.
i'm mismatching some calling ?
function getGroupDataById(id, ctrl) {
$.getJSON(
"api/groupvalues/GetDetails/" + id,
function (data) {
Is this related with Route?
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Upvotes: 0
Views: 448
Reputation: 2387
It really doesn't matter what you write after Get, it is going to call the first one with same arguments. Web API don't rely on name rather they rely on HTTP verbs.
Upvotes: 1
Reputation: 6526
Per the link below, in order to target that action method the way you have, you need to change your routing:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
http://www.codeproject.com/Articles/624180/Routing-Basics-in-ASP-NET-Web-API
Upvotes: 2