zoukankan      html  css  js  c++  java
  • 记录学习MVC过程,MVC简单路由(三)

    1.Table列表页加载数据的时候,删除

    <script src="../../Scripts/jquery-1.8.2.js"></script>
    <script type="text/javascript">
    $(function() {
    $("a:contains('删除')").click(function() {
    return confirm("请确认是否真的删除此数据?");
    });
    });
    </script>

    mvc可以把razor引擎和aspx引擎,不同页面可以使用不同的引擎-_-Razor的智能感应还是挺好用的

    @html.raw("<span>raw表示html标签不被编码成txt</span>")

    <%: Html.ActionLink("删除","Delete","UserInfo",new {UId=dataRow["Id"]},new {}) %>

     [HttpGet]//相同方法用GET还是post来区别是修改还是加载
            public ActionResult Edit(int Id)
            {
                return View();
            }
     [HttpPost]//相同方法用GET还是post来区别是修改还是加载
            public ActionResult Edit(UserInfo userInfo)
            {
                return RedirectToAction("Index");
            }
    

    2.路由规则

     //路由规则:
                //1、可以有多条路由规则
                //2、路由规则是有顺序的。前面被匹配了之后,后面就没有机会了。
     //注册一条路由规则
                routes.MapRoute(
                    name: "Default",//作为路由规则的key,一定不能重复
                    url: "{controller}/{action}/{id}",//请求后台URL规则
                    //http://localhost:23017/Home-Index
                    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//,//默认值
                    //constraints: new { controller=@"^w+$",id=@"^d+$"},//约束
                    //namespaces: new string[] { "MvcRazorDemo.Controllers" }//控制器命名空间的约束
                );
    
    
                //routes.MapRoute( 
                //    "酒店列表页",//路由规则名字
                //    "hotels/{action}-{city}-{price}-{star}", //路由规则的URL格式
                //    new { controller = "Hotel", action = "list", city = "beijing", price="-1,-1", star="-1" },//默认值
                //    new { city=@"[a-zA-Z]*",price=@"(d)+\,(d)+", star="[-1-5]"} 
                //);
                
                ////hotels/所有匹配 
                //routes.MapRoute( 
                //    "酒店首页",
                //    "hotels/{*写什么都可以}",
                //    new { controller = "Hotel", action = "default", hotelid = "" }
                //); 
    
                //routes.MapRoute(
                //    "网站首页",
                //    "{*values}", 
                //    new { controller = "Home", action = "index"} 
                //); 
    

     3.路由调试搜索到RouteDebug.dll并引用

    在Global.asax开启调试路由

     //路由调试设置代码
                //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);
    

     4.多条路由的时候,有顺序的,有些参数会被当作一个控制器或者视图用,而到不了下一条路由规则

    基础部分跳了好多......继续下一视频学习

    你将独自前行,你会遇到友好,也会遇到恶意,不管你多么善良,因为世间就是这样,不好,不坏.
  • 相关阅读:
    Character 比较注意先要转换成字符串类型
    ibats注意
    初试体验java多线程
    解压jar
    Velocity语法--转载
    python 批量请求url
    java.lang.NoClassDefFoundError
    疑问
    sql常用语句--转载
    Spring AOP高级——源码实现(3)AopProxy代理对象之JDK动态代理的创建过程
  • 原文地址:https://www.cnblogs.com/jsdvkm/p/4574892.html
Copyright © 2011-2022 走看看