1

I have a form and using Grid.MVC to display in same page. When I try run my program, it show error : 'Model' conflicts with the declaration 'System.Web.Mvc.WebViewPage.Model'..

Here the sample of my code

This is my 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; }
    } 

}

And this is my 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")
}

The error show on this line

@Html.Grid(Model.lCourse).Columns

Please advice...

Azri Zakaria
  • 1,324
  • 5
  • 23
  • 52

2 Answers2

1

Usually this means that you're using the reserved "Model" keyword erroneously somewhere. In your case:

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

Change this to:

@Html.DropDownListFor(model => model.CoursePackageID...
Mackan
  • 6,200
  • 2
  • 25
  • 45
  • Yes, well ... you have a problem before that :) Does the problem remain when you changed the above? – Mackan Mar 12 '15 at 07:55
  • The error indicates that you're using the reserved "Model" (with capital M) keyword somwhere else. I can't see any other reasons for the code to fail in your examples. – Mackan Mar 12 '15 at 08:20
  • Dear Mackan, my problem was solved... i don't know how to say but I follow your suggestion and and change a few code on the controller and now it's works..! Thanks mate... – Azri Zakaria Mar 12 '15 at 08:22
0

Try changing the line in question as below(lowercase 'm')...

@Html.Grid(model.lCourse).Columns
Dinesh
  • 470
  • 4
  • 13