So I am very new to MVC and development. What I am trying to do is basically create a single row table view of an user so that I can edit and update on that single row. (I hope I am making sense)
So I am using MVC Razor View and I want to create a table and edit within that table without using the CRUD functionality that is already built into MVC. I want to do inline editing of my tabular view.
So I have create a view that also has a partial view. I have a Model and my Repository as well. WHen I run this, it says Object not set to an instance of an object, and it's talking about my foreach loop. Here is the data below. If someone can offer assistance, that would be greatly appreciated. I am very new and only been really coding for about 3 months now.
Controller
public ActionResult Index(string id)
{
var attendee = (Guid)Membership.GetUser(id).ProviderUserKey;
CatalogAttendeeModel model = new CatalogAttendeeModel();
model.getAttendeesList(attendee);
var catalog = from ca in db.text
join a in db.text on ca.textID equals a.textID
where ca.textID== attendee
select ca;
foreach (var item in catalog)
{
if (item.IsActive == null)
{
item.IsActive = true;
}
}
return PartialView();
}
Index View
@model ODT4.Models.CatalogAttendeeModel
<table>
<thead>
<tr>
<th>
@Html.Label("Catalog")
@Html.Label("Role")
@Html.Label("Is Admin")
@Html.Label("Certificate Printed")
@Html.Label("Percent Watched")
@Html.Label("Percent Updated")
@Html.Label("PI Name")
@Html.Label("Action")
</th>
</tr>
</thead>
<tbody>
@foreach (var row in Model.catalogAttendees) //this is where I get the errormessage
{
{
Html.RenderPartial("CatalogAttendeeSingleRow", row);
}
}
</tbody>
</table>
Partial View
@model ODT4.Models.CatalogAttendeeModel
@{
<div id = "crud_tableEdit" >
<table>
<tr>
<td>@Html.DisplayFor(m => m.Catalog.CatalogCode)</td>
<td>@Html.DisplayFor(m => m.StudyRole)</td>
<td>@Html.DisplayFor(m => m.IsAdmin)</td>
<td>@Html.DisplayFor(m => m.IsTrainingDocPrinted)</td>
<td>@Html.DisplayFor(m => m.PercentWatched)</td>
<td>@Html.DisplayFor(m => m.PercentUpdatedOn)</td>
<td>@Html.DisplayFor(m => m.PIName)</td>
</tr>
</table>
</div>
}
CatalogModel
public List<Catalog_Attendee> catalogAttendees { get; set; }
public CatalogAttendeeModel()
{
}
public void getAttendeesList(Guid id)
{
//catalogAttendees = new List<Catalog_Attendee>();
CatalogAttendeeRepository rep = new CatalogAttendeeRepository();
catalogAttendees = rep.getAttendeesAll();
}
Repository
public List<Catalog_Attendee> getAttendeesAll()
{
return db.Catalog_Attendee.ToList();
}
public Catalog_Attendee getAttendeeByID(Guid id)
{
return db.Catalog_Attendee.FirstOrDefault(i => i.AttendeeID == id);
}
Here is the error message:
Server Error in '/' Application.
________________________________________
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 17: </thead>
Line 18: <tbody>
Line 19: @foreach (var row in Model.catalogAttendees)
Line 20: {
Line 21: {