I want to display the list of cities of each state in a modal form when the user clicks on that state. Unfortunately, whatever I did, I could not solve this problem. I will write the necessary codes for you. asp.net core I wrote
As you can see, in this query, we wrote two lines of code. In the first line, we applied a condition. When we apply the condition, nothing is displayed in the modal, but when we apply the second line, it means that we do not write the condition. Displays the database.
Query codes:
`public List ShowParishByCity(int id)
{
// return _context.Parishes.Where(c=>c.CityId==id).ToList();
return _context.Parishes.OrderBy(p => p.Name).ToList();
}`
Interface:
List<Parish> ShowParishByCity(int id);
Controller codes:
`public IActionResult ShowParish(int id)
{
var pareshList = _iadvert.ShowParishByCity(id);
var model = new ParieshViewModel
{
Parishes = pareshList,
};
return View(model);
}`
view:
`@model Paniaz.Core.ViewModels.ParieshViewModel
@{
Layout = null;
}
<div class="clearfix"></div>
<div style="height:1500px;width: 1238px;margin-right: -48px;">
<div class="col-lg-10 col-md-10">
@foreach (var item in Model.Parishes)
{
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-6 ">
<a asp-action="ShowAdverts" asp-controller="Home" asp-route-id="Id"
class="btn-city btn-block col-lg-2 text-center"
style="margin-right:20px;white-space:nowrap">
@item.Name
</a>
</div>
}
}
</div>
`
koorosh nadimi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.