コード例 #1
0
 public ActionResult FormWithBinding(Models.House h)
 {
     if (ModelState.IsValid)
     {
         ViewBag.added = true;
         HouseDBs.AddHouse(h);
     }
     return(View());
 }
コード例 #2
0
        public ActionResult PickAHouseForm(FormCollection data)
        {
            bool garage = false;

            if (data["Garage"] == "true")
            {
                garage = true;
            }

            bool yard = false;

            if (data["Yard"] == "true")
            {
                yard = true;
            }

            House h = new House
            {
                City       = data["City"],
                SquareFeet = data["SquareFeet"],
                Floors     = Convert.ToByte(data["Floors"]),
                Garage     = garage,
                Yard       = yard,
                Color      = data["Color"]
            };


            //Validate data for database
            if (HouseDBs.AddHouse(h))
            {
                ViewBag.HouseAdded = true;
                //add to database
            }

            return(View());

            //HouseDB db = new HouseDB();

            //db.Add(h);
        }