2

I am having this issue that keeps flagging up and I have checked every file. Just want to see if anyone else can spot an error?

@{
ViewBag.Title = "Event List";
}

<div>

Event Name : @Model.item.eventname <br />
Event Date : @Model.item.date <br />
Event Town : @Model.item.town <br />
Event Country : @Model.item.country <br />
Event Description : @Model.item.description <br />
Event Report : @Model.item.report <br />

@Html.ActionLink("Add New Event" , "AddEvent")


 @*Html.Partial("EventList")*@

</div>

All reply's are much appreciated !

Bellow is the Event Model which is linked to the orginal post:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace NETCW.Models
{
public class Event
{
    public int EventID { get; set; }

    [Required(ErrorMessage = "Please enter the event name.")]
    public string eventname { get; set; }

    [Required(ErrorMessage = "Please enter the event date.")]
    public string date { get; set; }

    [Required(ErrorMessage = "Please enter the event town.")]
    public string town { get; set; }

    [Required(ErrorMessage = "Please enter the event country.")]
    public string country { get; set; }

    [Required(ErrorMessage = "Please enter the event description.")]
    public string description { get; set; }

    [Required(ErrorMessage = "Please enter the event report.")]
    public string report { get; set; }

}
}

See bellow edited I am getting a error it says it does not contain a definition for the following Date, Town, Country and Report :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace NETCW.Models
{
public class Event
{
    public int EventID { get; set; }

    [Required(ErrorMessage = "Please enter the event name.")]
    [Display (Name = "Event Name :")]
    public string eventname { get; set; }

    [Required(ErrorMessage = "Please enter the event date.")]
    [Display (Date = "Event Date :")]
    public string date { get; set; }

    [Required(ErrorMessage = "Please enter the event town.")]
    [Display (Town = "Event Town :")]
    public string town { get; set; }

    [Required(ErrorMessage = "Please enter the event country.")]
    [Display (Country = "Event Country :")]
    public string country { get; set; }

    [Required(ErrorMessage = "Please enter the event description.")]
    [Display (Description = "Event Description :")]
    public string description { get; set; }

    [Required(ErrorMessage = "Please enter the event report.")]
    [Display (Report = "Event Report :")]
    public string report { get; set; }

}
}
4
  • What exactly is null? Commented Apr 14, 2015 at 1:01
  • 1
    item is most likely null. Have you checked it at runtime while debugging to ensure that it is not null? Commented Apr 14, 2015 at 1:01
  • 1
    Show the error details. Check if property item is null Commented Apr 14, 2015 at 1:02
  • Check the link for the photo for error snag.gy/GuHI3.jpg Commented Apr 14, 2015 at 1:07

1 Answer 1

3

You have not declared you model in the view. At the top of the view you need to declare it

@model NETCW.Models.Event

Edit

Based on the edited question @Model.item.eventname will also fail because Event does not contain a property named item. In addition you need to pass the model to the view, and you should be using the htlm helpers to generate the elements. In the GET method

Event model = new Event();
return View(model);

and in the view

@Html.DisplayFor(m => m.eventname)

and if your property is decorated with [Display(Name = "Event Name:")] then you can use the following to generate the associated label

@Html.DisplayNameFor(m => m.eventname)
Sign up to request clarification or add additional context in comments.

25 Comments

When you say YourAssembly you mean like: @model NETCW.Models.Event
You have not posted you model, but yes, something like that
That error is because the model is null. In the GET method, you need to return the model - e.g. var model = new Event(); return View(model);. And use the html helpers to generate your elements.
I have uploaded the Model of Events in the orginal post
Sorry, but no. You need to include the details in your question (SO is for helping other users as well). What is the it in "Not sure exactly where it needs to go"?. I'm not sure which bit you do not understand, or what problems your still having
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.