Model' 与 Grid.MVC (ASP.NET) 上的声明 Model 冲突

Model' conflicts with the declaration Model on Grid.MVC (ASP.NET)

我有一个表单并使用 Grid.MVC 在同一页面中显示。当我尝试 运行 我的程序时,它显示错误:'Model' 与声明 'System.Web.Mvc.WebViewPage.Model'..

冲突

这是我的代码示例

这是我的模型

public class Course
{
    [DisplayName("Customer Name")]
    public string customer { get; set; }

    [DisplayName("Contact")]
    public string contact { get; set; }

    [UIHint("DropDownList")]
    [Required(ErrorMessage = "Please select the package")]
    public int CoursePackageID { get; set; }

    [Required]
    public int CustomerID { get; set; }

    [Required(ErrorMessage = "The date is required")]
    [DisplayName("Date Of Register")]
    public DateTime dtRegister { get; set; }

    [DisplayName("Payment")]
    public string payment { get; set; }

    public List<CourseObject> lCourse { get; set; }

    public class CourseObject
    {       
        public int courseId { get; set; }

        [DisplayName("Package")]
        public string package { get; set; }
        [DisplayName("Date Of Register")]
        public DateTime date_register { get; set; }
        [DisplayName("Payment")]
        public string payment { get; set; }
    } 

}

这是我的 CSHTML (Razor)

@model BangiProject.Models.Course
@using GridMvc.Html
@{
    ViewBag.Title = "Register";
}
<h2>
    Register</h2>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Course</legend>
        <div class="control-label">
            @Html.LabelFor(model => model.customer)
        </div>
        <div class="form-control-static">
            @Html.DisplayFor(model => model.customer)
        </div>
        <div class="control-label">
            @Html.LabelFor(model => model.contact)
        </div>
        <div class="form-control-static">
            @Html.DisplayFor(model => model.contact)
        </div>
        <div class="editor-label">
            Category :
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(Model => Model.CoursePackageID, new SelectList(ViewBag.CoursePackage as System.Collections.IEnumerable, "id", "course_name", new { @style = "drop-down" }),
            "-Choose Package-", new { id = "cat" })
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.dtRegister)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.dtRegister)
            @Html.ValidationMessageFor(model => model.dtRegister)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.payment)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.payment)
            @Html.ValidationMessageFor(model => model.payment)
        </div>
        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}
<div class="row">
    @Html.Grid(Model.lCourse).Columns(columns =>
                    {
                        columns.Add(c => c.courseId).Titled("ID")
                            .Sanitized(false)
                            .Encoded(false)
                            .RenderValueAs(o => Html.ActionLink("Edit", "Edit", "Merchant", new { id = o.courseId }, null).ToHtmlString());

                        columns.Add(c => c.package).Titled("Package").Filterable(true);

                        columns.Add(c => c.date_register).Titled("Date Of Register").Filterable(true);


                    }).WithPaging(25).Sortable(true)
</div>
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

错误显示在这一行

@Html.Grid(Model.lCourse).Columns

请指教...

通常这意味着您在某处错误地使用了保留关键字 "Model"。你的情况:

@Html.DropDownListFor(Model => Model.CoursePackageID...

将此更改为:

@Html.DropDownListFor(model => model.CoursePackageID...

尝试如下更改有问题的行(小写 'm')...

@Html.Grid(model.lCourse).Columns