Click here to Skip to main content
15,912,021 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello all,

i need this support, i am presently following a video on udemy for my development in MVC, the issue i am having is that following the video and the instruction from the trainer has been nice but i have an issue of rendering the view from controller via the model. below is the error i get and codes in the files

1. Razor view without the @model IEnunerator<vidly.models.customers>

code:
Quote:
@model IEnumerable<vidly.models.customer>

@*
Note: I've set the model for this view to IEnumerable<customer>.
This is a simple interface implemented by the list class. Since
in this view we only want to iterate over this list, and we don't
need any of the operations in the List class (eg Add, Remove, etc),
it's better to use the IEnumerable interface, which allows use to
iterate over the list. If in the future, we replace the List with a
different data structure, as long as it is enumerable, our view code
will remain unchanged.
*@

@{
ViewBag.Title = "Customers";
Layout = "~/Views/Shared/_Layout.cshtml";
}

@*Customer count is: @Model.Count()*@

Customers


@if (!Model.Any())
{

We don't have any customers yet.


}
else
{

@foreach (var customer in Model)
{
/td>
}
Customer
@Html.ActionLink(customer.Name,"Details","Customers", new {id=customer.Id},null)

}


Error
Quote:
The wait operation timed out
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.ComponentModel.Win32Exception: The wait operation timed out

Source Error:


Line 21: public ViewResult Index()
Line 22: {
Line 23: var customers = _context.Customers.ToList();
Line 24:
Line 25: return View(customers);



2. Razor view with the @model IEnumerable<vidly.models.customer>

Code:
@*
Note: I've set the model for this view to IEnumerable<customer>.
This is a simple interface implemented by the list class. Since
in this view we only want to iterate over this list, and we don't
need any of the operations in the List class (eg Add, Remove, etc),
it's better to use the IEnumerable interface, which allows use to
iterate over the list. If in the future, we replace the List with a
different data structure, as long as it is enumerable, our view code
will remain unchanged.
*@

@{
ViewBag.Title = "Customers";
Layout = "~/Views/Shared/_Layout.cshtml";
}

@*Customer count is: @Model.Count()*@

Customers


@if (!Model.Any())
{

We don't have any customers yet.


}
else
{

@foreach (var customer in Model)
{
/td>
}
Customer
@Html.ActionLink(customer.Name,"Details","Customers", new {id=customer.Id},null)

}


Error

Quote:
Server Error in '/' Application.
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Vidly.Models.Customer]', but this dictionary requires a model item of type 'Vidly.ViewModels.RandomMovieViewModel'.


CustomerController:

Quote:
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Vidly.Models;

namespace Vidly.Controllers
{
public class CustomersController : Controller
{
private ApplicationDbContext _context;

public CustomersController()
{
_context = new ApplicationDbContext();
}

protected override void Dispose(bool disposing)
{
_context.Dispose();
}
public ViewResult Index()
{
var customers = _context.Customers.ToList();

return View(customers);
}

public ActionResult Details(int id)
{
var customer = _context.Customers.SingleOrDefault(c => c.Id == id);

if (customer == null)
return HttpNotFound();

return View(customer);
}

}
}


Customer Model:

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

namespace Vidly.Models
{
public class Customer
{
public int Id { get; set; }
[Required]
[StringLength(255)]
public string Name { get; set; }
public bool IsSubscribedToNewsletter { get; set; }
public MembershipType MembershipType { get; set; }
public byte MembershipTypeId { get; set; }

}
}


What I have tried:

I have checked on GIT and google but all the recommended fix has not worked, so i want to know the issue is associated with the VS version i am using or not, more so i am using VS2015
Posted
Updated 15-May-18 18:31pm
Comments
Member 12810461 14-May-18 14:09pm    
can you please share the url for the second error? which method is invoked when error occurs?
taiwokaffo 14-May-18 14:32pm    
Server Error in '/' Application.
The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Vidly.Models.Customer]', but this dictionary requires a model item of type 'Vidly.ViewModels.RandomMovieViewModel'.

1 solution

Error means what it says. The DB is timing out. Your code is fine
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900