我會通過@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