I am using an MVC controller to create a dynamic JavaScript file (I am not happy with that part, but I'm trying to maintain compatibility with a previous version) in a Web Api project...
The client is consuming a URL like:
~/api/assessments/{id:int}.js?locale={locale?}
I created an MVC JavaScriptController
and added a method like this:
[Route("~/api/data/{id:int}.js")]
public async Task<PartialViewResult> GetData(int id, string locale)
{
try
{
Response.ContentType = "application/javascript";
ViewBag.Locale = locale ?? "en";
var model = await this._dataService.GetData(id.ToString());
return PartialView(model);
}
catch (Exception ex)
{
this._logger.Error("Task<PartialViewResult> GetData(int, string)", ex);
return PartialView("JavaScriptError", SelectException(ex));
}
}
When I try to invoke this call, however, I get a 404:
<Error>
<Message>
No HTTP resource was found that matches the request URI 'http://.../api/data/29.js?locale=en'.
</Message>
<MessageDetail>
No type was found that matches the controller named 'data'.
</MessageDetail>
</Error>
I'm thinking that the WebApi "~/api" prefix is stepping on the MVC 5 route, although I suppose it could be something completely different. How can I render this MVC view at the specified URL?