标记助手未填充表单值

时间:2019-09-14 14:48:17

标签: c# asp.net-core .net-core asp.net-core-mvc

我正在尝试构建一个简单的MVC Core 2.1表单,但是由于某些原因,没有在浏览器中填充标签助手。

public async Task<IActionResult> Edit()
    {
        int websiteID = 0;

        websiteID = GetSessionStateInt("WebsiteId");

        if (websiteID == 0)
        {
            // (something went wrong)
            return NotFound();
        }
        else
        {
            // Get the home/mission statement details
            int WebsitesHomeId = 1;

            var tempId = _db.WebsitesHomeID.FromSql("EXEC [dbo].[GetWebsitesHomeID] @iWebsiteID", new SqlParameter("@iWebsiteID", websiteID));

            var WebsitesHome = await _db.WebsitesHome.FindAsync(WebsitesHomeId);
            if (WebsitesHome == null)
            {
                return NotFound();
            }

            return View(WebsitesHome);
        }

    }

这是CSHTML ...

    @model PHAwebsites.Models.WebsitesHome
@{
    ViewData["Title"] = "Home/Mission Statement";
    Layout = "~/Views/Shared/_Layout.cshtml";

}

<h2 class="text-info">Edit Home Info and Mission Statement</h2>

<div class="row">
    <div class="col-md-8">
        <form method="post" asp-action="Edit">
            <div class="p-4 border rounded row">
                <input type="hidden" asp-for="Id" />
                <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                <div class="col-12">
                    <div class="form-group row">
                        <div class="col-4">
                            <label asp-for="MissionStatement"></label>
                        </div>
                        <div class="col-8">
                            <input type="text" asp-for="MissionStatement" class="form-control" />
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

对我可能在这里缺少的任何想法吗?我在另一个工作正常的项目中拥有几乎相同的代码。我已经尝试了几乎所有可以想到的事情,并且整个上午(现在大约3个小时)都在寻找解决方案,因此,我们将不胜感激。

1 个答案:

答案 0 :(得分:2)

在_ViewImport.cshtml中,请确保您具有这一行

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers