Answer the question
In order to leave comments, you need to log in
Sending data from a form?
In an mvc project, I want to implement a search, and the results should be displayed in the block below, and not on another page.
the search form is in partial view, the list of found items is too.
search form:
<div>
@using (Ajax.BeginForm("_RealtyItemsList", new AjaxOptions { UpdateTargetId = "results" }))
{
<select class="form-select" id="realty-type" aria-label="Default select example" name="RealtyType" style="width:100px">
<option value[email protected]>@realtyStore.Models.Types.APARTMENT</option>
<option value[email protected]>@realtyStore.Models.Types.ROOM</option>
<option value[email protected]>@realtyStore.Models.Types.HOUSE</option>
<option value[email protected]>@realtyStore.Models.Types.BED</option>
<option value[email protected]>@realtyStore.Models.Types.GARAGE</option>
<option value[email protected]>@realtyStore.Models.Types.WAREHOUSE</option>
<option value[email protected]>@realtyStore.Models.Types.BUILDING</option>
<option value[email protected]_AREA>@realtyStore.Models.Types.TRADING_AREA</option>
<option value[email protected]>@realtyStore.Models.Types.PRODUCTION</option>
<option value[email protected]>@realtyStore.Models.Types.OFFICE</option>
</select>
<div class="input-group">
<p>Цена</p>
<input placeholder="от" name="minPrice" type="number" />
<input placeholder="до" name="maxPrice" type="number" />
</div>
<div class="input-group" id="square" style="display:none">
<p>Площадь</p>
<input placeholder="от" name="minSquare" type="number" />
<input placeholder="до" name="maxSquare" type="number" />
</div>
<div class="checkBox-group" id="numRooms">
Количество комнат
<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[email protected]>@c.Name</option>
}
</select>
<input id="search" type="submit" value="Поиск" />
}
<div id="results"></div>
</div>
<script src="@Url.Content("~/Scripts/formRent.js")" type="text/javascript"></script>
@model IEnumerable<realtyStore.Models.Realty>
@foreach (var r in ViewBag.Realties)
{
<div class="realtyItem">
<div class="realtyItem__img">
<a href="Flat/@r.Id"><img [email protected] alt="photo" /></a>
</div>
<div>
<a href="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>
}
[HttpPost]
protected ActionResult _RealtyItemsList(Realty realty)
{
return PartialView(realty);
}
Could not find this resource.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) may have been removed, renamed, or temporarily unavailable. Review the following URL and verify that it is entered correctly.
Requested URL: /Home/_RealtyItemsList
db.Owners.Add(new Owner { Id = 0, LastName = "Яковлева", FirstName = "Айлин", Patronymic = "Дмитриевна", Phone = "895102345612", Passport = "1420 777799", CityId = 2, Address = "" });
db.Owners.Add(new Owner { Id = 1, LastName = "Кошелев", FirstName = "Демид", Patronymic = "Матвеевич", Phone = "89997777777", Passport = "1418 774577", CityId = 0, Address = "" });
db.Owners.Add(new Owner { Id = 2, LastName = "Игнатов", FirstName = "Андрей", Patronymic = "Давидович", Phone = "89301234567", Passport = "1415 713757", CityId = 1, Address = "" });
db.Owners.ToList()[0].Id; // =1
db.Owners.ToList()[1].Id; // =2
db.Owners.ToList()[2].Id; // =3
Answer the question
In order to leave comments, you need to log in
You have a POST method, and you make an ajax request via GET (by default).
Try adding new AjaxOptions { HttpMethod = "Post" }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question