RealtyContext.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace realtyStore.Models
{
public class RealtyContext : DbContext
{
public DbSet<Realty> Realties { get; set; }
public DbSet<Buyer> Buyers { get; set; }
public DbSet<Realtor> Realtors { get; set; }
public DbSet<Owner> Owners { get; set; }
public DbSet<Sold> Sold { get; set; }
public DbSet<Leased> Leased { get; set; }
public DbSet<City> Cities { get; set; }
}
}
HomeController.cs
namespace realtyStore.Controllers
{
public class HomeController : Controller
{
RealtyContext db = new RealtyContext();
public ActionResult Index()
{
IEnumerable<City> cities = db.Cities;
IEnumerable<Realty> realties = db.Realties;
ViewBag.Realties = realties;
ViewBag.Cities = cities;
return View();
}
[HttpGet]
public ActionResult Flat(int? id)
{
Realty realty = null;
foreach(var r in db.Realties)
{
if (id != null && id == r.Id)
{
realty = r;
}
}
ViewBag.Realty = realty;
return View();
}
[HttpPost]
protected string Search(string city, string[] NumberRoom, string RealtyType)
{
return city + ' ' + RealtyType + ' ' + NumberRoom[0];
}
}
}
Home/Index.cshtml
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Home Page";
var RealtyType = "";
string[] NumberRoom;
if (IsPost)
{
RealtyType = Request.Form["RealtyType"];
NumberRoom = Request.Form.GetValues("NumberRoom[]");
}
}
@*@Html.partial("_realtyitemslist");*@ пишет, что html не существует в данном контексте. ?
<div>
<h3>Поиск недвижимости</h3>
<div class="search-form">
<form id="for-sale" method="post">
<select class="form-select" aria-label="Default select example" name="RealtyType" style="width:100px">
<option value=@realtyStore.Models.Types.APARTMENT>@realtyStore.Models.Types.APARTMENT</option>
<option value=@realtyStore.Models.Types.ROOM>@realtyStore.Models.Types.ROOM</option>
<option value=@realtyStore.Models.Types.HOUSE>@realtyStore.Models.Types.HOUSE</option>
<option value=@realtyStore.Models.Types.BED>@realtyStore.Models.Types.BED</option>
</select>
<div class="checkBox-group">
Количество комнат
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" value="1" id="flexCheckDefault" name="NumberRoom[]">
<label class="form-check-label" for="flexCheckDefault">
1
</label>
<input class="form-check-input" type="checkbox" value="2" id="flexCheckChecked" name="NumberRoom[]" checked>
<label class="form-check-label" for="flexCheckChecked">
2
</label>
</div>
</div>
<select class="form-select" aria-label="Default select example" name="City" style="width:100px">
@foreach (var c in ViewBag.Cities)
{
<option value=@c.Name>@c.Name</option>
}
</select>
<input id="Button1" type="submit" value="Поиск" />
</form>
</div>
@foreach (var r in ViewBag.Realties)
{
<div class="realtyItem">
<div class="realtyItem__img">
<a href="Home/Flat/@r.Id"><img src=@r.ImgUrl alt="photo" /></a>
</div>
<div>
<a href="Home/Flat/@r.Id"><p class="realtyItem__title">@r.Status @r.Type</p></a>
<p class="realtyItem__desc_mini">
@if (r.NumberRoom != null)
{<span>@r.NumberRoom -комн. </span>}
@r.Type, r.Squre кв.м.,
@if (@r.Floor != null)
{<span> @r.Floor /</span>} @r.Floors эт.
</p>
<p class="realtyItem__price"> @r.Price руб.</p>
</div>
</div>
}
</div>
Вызвано исключение: "System.Data.SqlClient.SqlException" в EntityFramework.dll
Исключение типа "System.Data.SqlClient.SqlException" возникло в EntityFramework.dll, но не было обработано в коде пользователя
Cannot drop database "realtyStore.Models.RealtyContext" because it is currently in use.
Home/Flat.cshtml
Realty не приходит в представление
@{
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="realtyItem">
<div class="realtyItem_left">
<img href=@ViewBag.Realty.ImgUrl alt="photo" />
<p class="realtyItem__title">
@ViewBag.Realty.Status
@if (ViewBag.Realty.NumberRoom != null)
{<span>@ViewBag.Realty.NumberRoom -комн. </span>}
@ViewBag.Realty.Type, r.Squre кв.м.,@if (@ViewBag.Realty.Floor != null)
{<span> @ViewBag.Realty.Floor /</span>} @ViewBag.Realty.Floors эт.
</p>
<p class="realtyItem__desc">@ViewBag.Realty.Description</p>
</div>
<div class="realtyItem_right">
<p class="realtyItem__price">@ViewBag.Realty.Price </p>
<asp:Button ID=@ViewBag.Realty.Id runat="server" Text="Показать номер телефона" OnClick="ShowPhone_Click" />
</div>
</div>
еще не подхватываются css, которые не bootstrap. Почему?