MVcルート検索、ルートはいったいどんな役割がありますか??

7025 ワード

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);

        }

    }

}

2つのビューのコード
@{

    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>@[email protected]</li>

             }

        </ol>

    </div>

</body>

</html>