我会通过@RedFilter
/things/list -- HTML
/things/_list -- return HTML help and examples (more for you than them).
/things/_list/schema -- schema info
/things/_list/json -- JSON format
/things/_list/xml -- XML format
/things/_list/csv -- csv format
/things/_list/tab -- tab deliminated format
/things/_list/wdsl -- implemented soap web service
等建议的轻微变化/阐述的建议。我觉得这是更具扩展性。它看起来很可怕,但很容易通过基于请求格式的装饰器传递数据内容,使得几乎所有的文件格式都可用,只需几行代码。
这里是粗概念例如:
public ActionResult _list(string id)
{
string data = "";
DataTable oDataTable = this.oDAO.Get("list"); // pretend data retrieval
try{
if(!String.IsNullOrEmpty(id)){
data = this.oDecorator.FormatData(id,oDataTable);
this.ContentTypeChange(id); // change application handler
}else{
data = this.GetHelp("_list");
}
}catch{}
ViewData["data"] = data;
return View();
}
...帮助下,可更多的是功能列表,技术的例子,或任何你想要的。当然,您可以从拥有本机JSON开始,并随着需求增长而添加更多数据格式给您的装饰器,这很好。对于我的许多项目,它开始时是由AJAX提供纯粹的json rest,并且倾向于根据网站流行度绽放为其他需要的格式,所以我发现这种方法足够强大,可用于企业环境中,适用于经常增长的小型项目大。
请看看[Action Naming Convention]上的回答(http://stackoverflow.com/questions/118474/action-naming-convention/38994001#38994001)。希望这有助于... – 2016-08-17 10:25:58