Is it possible to set the routing in a way that it detects ".json" or ".xml" at the end of my url? And How would I read that, Is it possible not to read that parameter by adding a parameter to my action method? I rather not use a query string for this purpose, it just seems ugly to me.
MyWebsite/Controller/MyAction.json
MyWebsite/Controller/MyAction.xml
MyWebsite/Controller/MyAction.otherType
---
public ActionResult MyAction()
{
var myData = myClient.GetData();
return SerializedData(myData);
}
private ActionResult SerializedData(Object result)
{
String resultType = SomeHowGetResultTypeHere;
if (resultType == "json")
{
return Json(result, JsonRequestBehavior.AllowGet);
}
else if (resultType == "xml")
{
return new XmlSerializer(result.GetType())
.Serialize(HttpContext.Response.Output, sports);
}
else
{
return new HttpNotFoundResult();
}
}