zoukankan      html  css  js  c++  java
  • 一个.net mvc的例子

     控制器 ( Controller) Product

    下面功能主要根据多条件搜索产品的列表的功能

     public ActionResult ProductList(string cityID, string productType,string currentPageIndex,string sortType)
            {
                SearchConditionInfo condtions = new SearchConditionInfo();
                if (string.IsNullOrEmpty(cityID))
                {
                    cityID = "17";
                }
                if (string.IsNullOrEmpty(productType))
                {
                    productType = ProductType.Hotel;
                }
                if (string.IsNullOrEmpty(sortType))
                {
                    sortType = SortType.Default;
                }
                if (string.IsNullOrEmpty(currentPageIndex))
                {
                    currentPageIndex = "1";
    
                }
                condtions.CityID =cityID;
                condtions.Topcount = "300";
                condtions.ItemType = productType;
                condtions.SortType = sortType;
                condtions.PageSize = "30";
                condtions.SortType = sortType;
                
        
                List<ProductInfo> GroupProductInfoList = APIRequsetClient.ProductList(condtions);
              
              
                PagedList<ProductInfo> ProductPageList = GroupProductInfoList.AsQueryable().ToPagedList<ProductInfo>(int.Parse(currentPageIndex), 30);
                ProductPageList.TotalItemCount =GroupProductInfoList.Count;
                ProductPageList.CurrentPageIndex =int.Parse(currentPageIndex);
               
               
                return View( ProductPageList);
                
                
            }
            

    视图 View

       接着我们需要有一个在视图做一个超链接这个链接跳到产品列表页ProductList

      @Html.RouteLink("这个是产品分类导航的某一项", "ProductListPage", new { cityID = Model.CurrentCityID, productType = ProductType.Hotel } })   

    路由配置(重点

    string url = "{0}.html";
    routes.MapRoute(
    "ProductListPage",//Route name
    string.Format(url, "sx/cnblogs/test/{cityID}/{productType}/{currentPageIndex}/{sortType}"),//URL with parameters
    new { controller = "Product", action = "ProductList", cityID = "155", productType = "13", currentPageIndex = 1, sortType = 0 }
    
    );
  • 相关阅读:
    MVC模型验证
    AutoMapper完成Dto与Model的转换
    【转】Asp.Net MVC及Web API框架配置会碰到的几个问题及解决方案
    MVC过滤器详解
    IOC框架Ninject实践总结
    【转】NHibernate对象以及状态说明
    轻量级IOC框架:Ninject (上)
    mysql5.7 误删管理员root账户
    杂项
    X-Pack权限控制之给Kibana加上登录控制以及index_not_found_exception问题解决
  • 原文地址:https://www.cnblogs.com/sunxi/p/4222243.html
Copyright © 2011-2022 走看看