I'm running a project in NET Core 2.1.1 with Visual Studio 2017 and I have the following problem:
A view is not generating the corresponding HTML.
I have the following controller:
public class CountryController : Controller {
IUnitOfWork Context;
IRepository<Country> countryRepository;
public CountryController(IUnitOfWork context) {
countryRepository = context.GetRepository<Country>();
Context = context;
}
public IActionResult Index() {
CountryViewModel countries = new CountryViewModel(countryRepository.Elements());
return View(countries);
}
public IActionResult Insert (CountryBindingModel country) {
Country Country = new Country();
Country.Name = "Canada";
countryRepository.Insert(Country);
Context.Save();
return RedirectToAction("Index");
}
}
I have the associated view:
@using Domain.Models
@model CountryViewModel
<form asp-controller="Country" asp-action="Insert">
<label asp-for="Name"></label>
<input class="form-control" asp-for="Name"/>
<button type="submit">Add Country</button>
</form>
<ul>
@foreach (var a in Model.Countries) {
<li>@(a.Name)</li>;
}
</ul>
The HTML it generates is the following, taken from the browser, and it does not work to add the country:
<form asp-controller="Country" asp-action="Insert">
<label asp-for="Name"></label>
<input class="form-control" asp-for="Name"/>
<button type="submit">Add Country</button>
</form>
<ul>
</ul>