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