Vivek Mishra
Vivek Mishra

Reputation: 1804

No action was found on the controller 'UpTourism' that matches the request.- MVC4 web api

I have created a web api in mvc 4. my controller is-

 [HttpPost]
    public string signIn(string socialId, string email)
    {
        try
        {
            using (TourismModelContainer db = new TourismModelContainer())
            {
                var user = (from log in db.UserDetails
                            where ((log.FacebookId == socialId || log.GoogleId == socialId) && log.IsActive==true)
                            select new { log.Id, log.Mobile, log.Gender, log.Country }).FirstOrDefault();
                if (user != null)
                {
                    string json = new Utills().ObjectToJson(user); ;
                    if (email == null || email == "")
                    {
                        return json;
                    }
                    else
                    {
                        bool isEmail = db.UserDetails.Where(o=>o.IsActive==true).Any(obj => obj.Email == email);
                        if (isEmail)
                            return "1";
                        else
                            return json;
                    }
                }
                else
                {
                    return "-1";
                }
            }
        }
        catch (Exception ex)
        {
            return "";
        }
    }

my WebApiConfig.cs file is

 public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{action}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

and my route config is -

 public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "api/{controller}/{action}/{id}",
            defaults: new { id = UrlParameter.Optional }
        );
    }

but when i call this sign in service, I get following error-

{ "Message": "No HTTP resource was found that matches the request URI 'http://localhost:58851/api/UpTourism/signIn'.", "MessageDetail": "No action was found on the controller 'UpTourism' that matches the request." }

Please help me regarding this.

Upvotes: 2

Views: 3249

Answers (1)

Amit Kumar Ghosh
Amit Kumar Ghosh

Reputation: 3726

Try this:

During HttpPost you can send only one parameter to action.So clubbing the two parameters you have inside a class and sending that object is much easier and convenient.I created a Demo class.And my controller is CustomController.

enter image description here

enter image description here

enter image description here

Upvotes: 3

Related Questions