Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7948909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:51:23+00:00 2026-06-04T01:51:23+00:00

I just started doing MVC 4 and I’ve been enjoying it quite a bit,

  • 0

I just started doing MVC 4 and I’ve been enjoying it quite a bit, but I’m running into trouble when I’m trying to get my database (just NAME and EMAIL entries) to show all its entries in the index view. I get the following error:

The model item passed into the dictionary is of type ‘System.Collections.Generic.List1[MobileWebFormver2.Models.WebForm1]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MobileWebFormver2.Models.User]’.

I was able to connect the program to the database, but I’m pretty much stuck here. I was wondering if I could get some help. Here’s my code:

User Class

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

namespace MobileWebFormver2.Models
{
    public class User
    {
        [Required(ErrorMessage="Please enter name.")]
        public string Name { get; set; }
        [Required(ErrorMessage="Please enter email.")]
        public string Email { get; set; }
    }
}

HomeController (WebForm1 is a database entry, that contains a NAME and EMAIL field)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MobileWebFormver2.Models;
using System.Data.Entity;

namespace MobileWebFormver2.Controllers
{
    public class HomeController : Controller
    {
        DataClasses1DataContext db = new DataClasses1DataContext();

        public ActionResult Index()
        {
            ViewBag.Message = "This is the TourEast Holidays Mobile Index";

            return View(db.WebForm1s.ToList());
        }
    }
}

Index

@model IEnumerable<MobileWebFormver2.Models.User>

@{
    ViewBag.Title = "Home Page";
}

@foreach (var item in Model)
{
    <tr>
        <td>
        @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
        @Html.DisplayFor(modelItem => item.Email)
        </td>
    </tr>
}

EDIT: This refers to DataClasses1DataContext. I’m not sure how useful this will be.

DataClasses1.cs

namespace MobileWebFormver2.Models
{
    partial class DataClasses1DataContext
    {
    }
}

DataClasses1.designer.cs

#pragma warning disable 1591
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.269
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace MobileWebFormver2.Models
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;


[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="MobileWebForm")]
public partial class DataClasses1DataContext : System.Data.Linq.DataContext
{

    private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertWebForm1(WebForm1 instance);
partial void UpdateWebForm1(WebForm1 instance);
partial void DeleteWebForm1(WebForm1 instance);
#endregion

    public DataClasses1DataContext() : 
            base(global::System.Configuration.ConfigurationManager.ConnectionStrings["MobileWebFormConnectionString"].ConnectionString, mappingSource)
    {
        OnCreated();
    }

    public DataClasses1DataContext(string connection) : 
            base(connection, mappingSource)
    {
        OnCreated();
    }

    public DataClasses1DataContext(System.Data.IDbConnection connection) : 
            base(connection, mappingSource)
    {
        OnCreated();
    }

    public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
            base(connection, mappingSource)
    {
        OnCreated();
    }

    public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : 
            base(connection, mappingSource)
    {
        OnCreated();
    }

    public System.Data.Linq.Table<WebForm1> WebForm1s
    {
        get
        {
            return this.GetTable<WebForm1>();
        }
    }
}

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.WebForm1")]
public partial class WebForm1 : INotifyPropertyChanging, INotifyPropertyChanged
{

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

    private string _Name;

    private string _Email;

#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnNameChanging(string value);
partial void OnNameChanged();
partial void OnEmailChanging(string value);
partial void OnEmailChanged();
#endregion

    public WebForm1()
    {
        OnCreated();
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Name", DbType="NVarChar(50) NOT NULL", CanBeNull=false, IsPrimaryKey=true)]
    public string Name
    {
        get
        {
            return this._Name;
        }
        set
        {
            if ((this._Name != value))
            {
                this.OnNameChanging(value);
                this.SendPropertyChanging();
                this._Name = value;
                this.SendPropertyChanged("Name");
                this.OnNameChanged();
            }
        }
    }

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Email", DbType="NVarChar(50) NOT NULL", CanBeNull=false)]
    public string Email
    {
        get
        {
            return this._Email;
        }
        set
        {
            if ((this._Email != value))
            {
                this.OnEmailChanging(value);
                this.SendPropertyChanging();
                this._Email = value;
                this.SendPropertyChanged("Email");
                this.OnEmailChanged();
            }
        }
    }

    public event PropertyChangingEventHandler PropertyChanging;

    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void SendPropertyChanging()
    {
        if ((this.PropertyChanging != null))
        {
            this.PropertyChanging(this, emptyChangingEventArgs);
        }
    }

    protected virtual void SendPropertyChanged(String propertyName)
    {
        if ((this.PropertyChanged != null))
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
}
 #pragma warning restore 1591'

I looked at similar posts here and I know it has to do with passing an object, but the view is expecting something else. However I would say I’m a very beginner level programmer and I don’t think I understood most of what they were saying. I basically followed the code from the MVC tutorial site (Link) from Microsoft on how to show your database in the index, but I’m getting the error. Any guidance would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:51:24+00:00Added an answer on June 4, 2026 at 1:51 am

    The problem is that you’re passing the wrong thing into the view. You’re passing a collection of WebForm1‘s, not User‘s.

    Edit –
    Change your view model to this:

    @model IEnumerable<MobileWebFormver2.Models.WebForm1>
    

    Edit – a bit more explanation:

    On this line, you are creating the ActionResult and passing in the data for the model.

    return View(db.WebForm1s.ToList());
    

    However, db.WebForm1s is a collection of type WebForm1.

    In your view, you are making a strongly typed view when you declare the model:

    @model IEnumerable<MobileWebFormver2.Models.User>
    

    The view expects a collection of users, but is passed WebForm1 instead. Hence the error – you have to decide which one is correct, the controller passing in WebForm1, or the view, and change the other to match.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started doing some PowerShell scripting, and I'm running into a problem testing
This may be a bit silly question, but I just started doing pretty things
We have just started doing scrum at my company. We are spending a bit
Just started doing some code porting from .Net CF to Blackberry JDE 4.6.1. But
I'm trying to get started with session-scoped beans in Spring Web MVC 3. I
I just started doing some reading (new to xcode/iphone development) into web services and
I have been searching for hours, I have just started doing Blackberry OS 6
I just started to get into the door of the Java world. I have
I have just started doing some ImageMagick work. I am currently trying to convert
I have just started to use Github and have been doing some tests with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.