剃刀:缺少一个或多个编译参考

时间:2018-03-06 22:09:21

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

我在剃刀页面中遇到ViewModel的问题,因此ViewModels命名空间无法识别并导致以下错误:

enter image description here

如果我将ViewModel的命名空间更改为App.Model或更改为App.Models.AccountViewModel(另一个ViewModel命名空间),则不会触发上述错误,并且页面会加载并正常运行。

有没有人对我做错了什么有任何想法?

视图模型:

namespace App.Models.DocumentViewModels 
{
    public class UploadDocumentViewModel
    {
        [Required]
        [Display(Name = "Document Type")]
        public string DocumentType { get; set; }

        [Display(Name = "Document Number")]
        public string DocumentNumber { get; set; }

        [Display(Name = "Document Expiry")]
        [DataType(DataType.Date)]
        public DateTime DocumentExpiry { get; set; }

        [Display(Name = "Shared Status")]
        public bool SharedStatus { get; set; } = false;
    }
}

RazorPage:

@model UploadDocumentViewModel

    @{
        ViewData["Title"] = "Upload Document";
    }

    <h2>@ViewData["Title"]</h2>

    <div class="row">
        <div class="col-md-4">
            <form asp-route-returnUrl="@ViewData["ReturnUrl"]" method="post">
                <h4>Upload a new document.</h4>
                <hr />
                <div asp-validation-summary="All" class="text-danger"></div>
                <div class="form-group">
                    <label asp-for="DocumentType"></label>
                    <input asp-for="DocumentType" class="form-control" />

                </div>
                <div class="form-group">
                    <label asp-for="DocumentNumber"></label>
                    <input asp-for="DocumentNumber" class="form-control" />

                </div>
                <div class="form-group">
                    <label asp-for="DocumentExpiry"></label>
                    <input asp-for="DocumentExpiry" class="form-control" />

                </div>
                <div class="form-group">
                    <div class="checkbox">
                        <label asp-for="SharedStatus">
                            <input asp-for="SharedStatus" />
                             @Html.DisplayNameFor(m => m.SharedStatus)
                        </label>
                    </div>
                </div>
                <button type="submit" class="btn btn-default">Upload</button>
            </form>
        </div>
    </div>

    @section Scripts {
        @await Html.PartialAsync("_ValidationScriptsPartial")
    }

0 个答案:

没有答案