一个.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 }

);

 

ASP.NET MVC一个用于构建Web应用程序的开发框架,它采用了模型-视图-控制器(Model-View-Controller,简称MVC)的设计模式。 下面是一个简单的ASP.NET MVC示例: 首先,我们可以创建一个控制器类。控制器负责处理用户的请求并返回响应,它可以包含多个动作方法。例如,我们可以创建一个名为HomeController的控制器类,其中包含一个名为Index的动作方法: ```csharp public class HomeController : Controller { public ActionResult Index() { return View(); } } ``` 然后,我们可以创建一个视图文件。视图负责展示数据给用户,并且通常与控制器的动作方法一一对应。在这个例子中,我们可以创建一个名为Index.cshtml的视图文件: ```html <!DOCTYPE html> <html> <head> <title>Home Page</title> </head> <body> <h1>Welcome to my website!</h1> </body> </html> ``` 最后,我们可以创建一个路由来处理URL和控制器之间的映射关系。路由确定了如何解释请求URL并调用相应的控制器和动作方法。在全局.asax.cs文件中,我们可以添加以下路由配置: ```csharp public class MvcApplication : System.Web.HttpApplication { protected void Application_Start() { // 路由配置 RouteConfig.RegisterRoutes(RouteTable.Routes); } } ``` 这个例子中,我们创建的路由将默认的URL(例如http://example.com/)映射到HomeController的Index动作方法。 当用户访问我们的网站首页时,控制器会处理请求并返回Index视图。然后,网站会显示一个简单的欢迎消息。 这只是一个简单的ASP.NET MVC示例,ASP.NET MVC框架还有很多其他功能和特性,可以帮助我们构建更复杂的Web应用程序。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值