zoukankan      html  css  js  c++  java
  • MVc路由查询,路由到底有什么作用呢??

    Model里的查询方法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace MvcApplication路由联系.Models
    {
        public class CarBF
        {
    
            private mastercarDataContext _Context = new mastercarDataContext();
            public List<Car> Select()
            {
                return _Context.Car.ToList();
            }
                public List<Car>  Selectbybrand(string brandcode)
                {
                    var query=_Context.Car.Where(p=>p.Brand==brandcode);
                    return query.ToList();
                }
                public List<Car> Selecbyprice(decimal low,decimal upp)
                {
                    var query = _Context.Car.Where(p=>p.Price>=low &&p.Price<=upp);
                    return query.ToList();
                }
        }
    }

    控制器里的代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using MvcApplication路由联系.Models;
    
    namespace MvcApplication路由联系.Controllers
    {
        public class HomeController : Controller
        {
            //
            // GET: /Home/
    
            public ActionResult Index()
            {
                return View();
            }
            public ActionResult Findbyprice(decimal low,decimal upp)
            {
                List<Car> list = new CarBF().Selecbyprice(low,upp);
                return View(list);
            }
        }
    }


    两个视图的代码

    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Index</title>
    </head>
    <body>
        <div>
            @using(Html.BeginForm("Findbyprice","Home",FormMethod.Post))
            {
                <div>
                最高价格:@Html.TextBox("low");
                最低价格:@Html.TextBox("upp");
                 </div>
            <input id="Submit1" type="submit" value="查询" />
            }
        </div>
    </body>
    </html>
    
    
    
    
    
    @using  MvcApplication路由联系.Controllers;
    @using MvcApplication路由联系.Models;
    @model List<Car>
    @{
        Layout = null;
    }
    
    <!DOCTYPE html>
    
    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>Findbyprice</title>
    </head>
    <body>
        <div>
           
            <ol>
                 @foreach(Car data in Model){
                <li>@data.Name@data.Price</li>
                 }
            </ol>
        </div>
    </body>
    </html>
  • 相关阅读:
    Cannot find module 'express'
    txt简单写入
    URLRewriter 伪静态配置Demo
    利用css的sticky特性实现固定首列其他列滚动
    金数据表单接口请求(php)
    Android应用app数据请求捕捉三步走
    go语言模块开发概念与cron定时事务模块的使用
    万维网的发明
    UEditor扩展又拍云图片存储功能实践
    Html5+移动端小应用分享(得见)
  • 原文地址:https://www.cnblogs.com/275147378abc/p/4644902.html
Copyright © 2011-2022 走看看