I realy want your option. We update a .net MVC 3 project to MVC 4 with web api 2, this a web service. The ajax calls is from android machines with the Devextreme/Phonegap.
After the update the web service when i call login from android i get "No HTTP resource was found that matches the request URI 'http://www.whatever.gr/MVCService/Actions/Login'"
I want to set the route so that all methods of the MVC service can have parameters optional. I can't get this work..
We can't change the source on the android app,and ajax call is the code below
function doLogin(username, password, callback) {
loading(true);
var dataStr = "uid=" + uid + "&username=" + username + "&password=" + password;
var success = false;
var token = "";
$.ajax({
type: "POST",
url: registrationServiceUrl + 'Login',
data: dataStr,
beforeSend: function () {
//alert("registration no: " + registrationid);
},
success: function (retval) {
if (retval.indexOf('SUCCESS') == 0) {
success = true;
token = retval.substring(8);
//setTokenToSettings(token);
} else {
success = false;
};
callback(success, token);
loading(false);
},
error: function (retval) {
callback(success, token);
loading(false);
}
});
}
The route in MVC is
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
//config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
When i hit like below with parameters in a browser i have a response 'http://www.whatever.gr/MVCService/Actions/Login?param1=1¶m=2¶m3=3'.
I want to have the behavior, when to hit 'http://www.whatever.gr/MVCService/Actions/Login' or 'http://www.whatever.gr/MVCService/Actions/Login?param1=1¶m=2¶m3=3&invalidParamName=x'.
And the web service method to be trigger with empty parameters values.
But without setting optional parameters in the method
public string Login(string pamar1 = "",string param2 = "", string param3 = "")
With MVC 3 this was working fine as I explained before.
Thanks in advance and for your time.