ASP.NET MVC 伪静态的实现

本文详细介绍了在MVC应用中如何通过路由配置和搜索模型实现高效的数据展示与过滤功能,包括配置路由规则、创建搜索模型类以及在控制器中处理搜索请求的过程。同时,文章还强调了在Web.config文件中正确配置模块的重要性,以确保HTML页面能够正常运行。
public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute("Category",
                       "list/{filterAttr}-{cateId}-{brandId}-{sortColumn}-{page}.html",
                       new { controller = "Home", action = "Index", id = UrlParameter.Optional });

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    }
public class SearchModel
    {
        public int BrandId { set; get; }
        public int FilterAttr { get; set; }
        public int CateId { get; set; }
        public int SortColumn { get; set; }
        public int Page { get; set; }
    }
public ActionResult Index( SearchModel model )
        {
            return View(model);
        }
@{
    ViewBag.Title = "Index";
}
@model MvcApplication3.Models.SearchModel
<h2>Index</h2>
@Html.RouteLink("aa","Category") 
FilterAttr:@Model.FilterAttr<br />
CateId:@Model.CateId<br />
BrandId:@Model.BrandId<br />
SortColumn:@Model.SortColumn<br />
Page:@Model.Page<br />

 

最后记得Web.config配置:

 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"></modules>

这个配置了之后就意味着html都走应用程序管道了,不知道怎么处理?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值