Hello fellow programmers
I am sitting trying to do something with MVC3. Just exploring the library. Not doing anything fancy. I have created a project and a controller. Now I am trying to let MVC3 to allow me to do fx http://localhost/MyController.json, http://localhost/MyController.xml or just http://localhost/MyController. In the .json and .xml examples I get errors. The third is of course allowed. I have tried to google this, but I do not get anything that helps me.
Can anyone here tell me how to allow file extension in MVC3?
Thanks.
EDIT I开发者_JAVA技巧 have not made any changes to the IIS like mapped file extensions.
You should add a route that includes an extension:
routes.MapRoute("ExtensionRoute",
"/{controller}.{extension}",
new { action="Index", extension = UrlParameter.Optional
);
This example maps the extension to a parameter in the action.
You can also make a route with a hard-coded extension.
精彩评论