1

假设我正在开发汽车门户。为了搜索新车,用户提供以下信息:

  • 模型
  • 型号版本
  • 汽油种类
  • 预算

商业规则:

  1. 如果用户仅选择品牌:显示品牌列表页面,其中包含所选品牌的所有型号
  2. 如果用户选择品牌和型号:显示型号列表页面
  3. 如果用户选择品牌 + 型号 + 型号版本:显示型号版本详细信息页面。
  4. 如果用户选择燃料类型或预算:显示品牌列表页面。

现在我有两种方法来定义控制器和动作。

方法 1:一个具有多个操作方法的 Controller 类

Controller Class : CarSearchmanager
with following are Action Methods:
        - SearchNewCar(int Barnd,int Model.......)
          Depending on user selection this method will redirect control to following  
          action method:

        - BrandListing(int BrandID......)
        - ModelListing(int BrandID,intModelID.....)
        - ModelVersionDetails((int BrandID,intModelID,int ModelVersionID....)

方法二:多控制器类

Controller Class : CarSearchmanager

Following are Action Methods:
        - SearchNewCar(int Barnd,int Model.......)
          Depending on user selection this method will redirect control to following 
          controller action method:

Then I will have separate controller class and action method for each of the pages like 
bellow:

    - BrandListing
    - ModelListing
    - ModelVersionDetails

我对如何组织控制器类和操作方法感到非常困惑。是否有任何最佳实践类型的文档?请给我推荐一个。

4

2 回答 2

1

我认为没有确定的最佳版本。以一种让您感觉更干净和更有条理的方式定义它。根据我对您的要求的理解,我可以这样定义

品牌控制器

行动方法

  • ListForFuleAndBudget(string fuelType,string budget)
  • List(string brandName)

模型控制器

动作方法

  • List(string brand,string model)
  • Details(string brand, string model, string version)

现在,如果您想要漂亮的 url,而您不想要操作方法名称,(例如:details)您可以在通用路由定义之前在 global.asax 中注册路由时定义漂亮的 url。

routes.MapRoute("list", "model/{brand}/{model}",
               new { controller = "brand", action = "List");

routes.MapRoute("list", "model/{brand}/{model}/{version}",
               new { controller = "brand", action = "details");

//default route definition goes here

现在yoursitename/model/honda/camry将把用户带到listaction 方法, yoursitename/model/honda/camry/lx并将他们带到detailsaction 方法。

于 2012-10-13T16:57:33.003 回答
0

我的建议是将它放在同一个控制器中,因为这是一个搜索功能,将在类似的上下文中使用。使用方法重载并在相应的方法中返回特定的视图。

于 2012-10-13T16:00:40.390 回答