我正在使用 Visual Studio 2017 在 NET Core 2.1.1 中運行一個項目,但遇到以下問題:視圖未生成相應的 HTML。我有以下控制器: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"); }}我有相關的觀點:@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>它生成的 HTML 如下,取自瀏覽器,添加國家/地區不起作用:<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>
1 回答

慕田峪9158850
TA貢獻1794條經驗 獲得超7個贊
標簽助手是可選的,需要您導入它們才能工作。
確保您的 Views 文件夾中有一個名為 _ViewImports.cshtml 的文件,并確保它添加了您想要的助手名稱空間。
例如,對于所有默認的 MS 助手,請使用以下內容:
@using AuthoringTagHelpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, AuthoringTagHelpers
- 1 回答
- 0 關注
- 102 瀏覽
添加回答
舉報
0/150
提交
取消