使用提供的默認路由,我不得不命名我的參數「id」。這對很多控制器操作都很好,但我想在某些地方使用一些更好的變量命名。是否有某種屬性可以使用,以便我的動作簽名中可以包含更多有意義的變量名稱?動作參數命名
// Default Route:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = "" } // Parameter defaults
);
// Action Signature:
public ActionResult ByAlias(string alias)
{
// Because the route specifies "id" and this action takes an "alias", nothing is bound
}
這是使用綁定的最好的例子,我找到了!有沒有辦法讓這個模型屬性的工作?即代替具有字符串參數的方法簽名,它具有一個類作爲具有如下所示的屬性的參數:'[Bind(Prefix =「id」)] string Alias {get;設置;}'?這個例子不編譯...我怎麼修改它來編譯(也是工作)? – 2011-09-08 17:00:18