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 8714309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:34:01+00:00 2026-06-13T05:34:01+00:00

My question is related to a beginner’s topic (sorry for that…). I’m just starting

  • 0

My question is related to a beginner’s topic (sorry for that…). I’m just starting with MVC and at this moment i’m trying to understand the concepts and strucute

I came from webform way of doing things and now i need to simulate the old webform repeater into MVC. Looking for an alternative on the web i discovered that foreach loops are one of the MVC’s way of achieving this, correct ?

Then i bit of context (and please, correct me if something i say indicates a wrong understanding of some concept)…

This is my model class created via edmx file

    public partial class qryMonitor
{
    public int Nsu { get; set; }
    public string NomeDaSolicitacao { get; set; }
    public string Grupo { get; set; }
    public string Prioridade { get; set; }
    public string Transito { get; set; }
    public Nullable<int> IdDestinatario { get; set; }
    public string NomeAutor { get; set; }
    public string DepartamentoAutor { get; set; }
    public int IdAutor { get; set; }
    public Nullable<int> IdAnalistaDesignado { get; set; }
    public string NomeAnalistaDesignado { get; set; }
    public Nullable<int> IdSuperiorAnalistaDesignado { get; set; }
    public string NomeSuperiorAnalistaDesignado { get; set; }
    public string Atividade { get; set; }
    public string CodigoRgb1 { get; set; }
    public string DataSolicitacao { get; set; }
    public int MarcarSolicitacao { get; set; }
}

Then i created another class with a single property…

public class ChamadosViewModel
{
    public IEnumerable<qryMonitor> Chamados { get; set; }
}

Now my controller’s code

public ActionResult Index()
{   
    EntidadesHelpDesk _dbHelpDesk = new EntidadesHelpDesk();
    ChamadosViewModel viewModel = new ChamadosViewModel()
    {
        Chamados = _dbHelpDesk.qryMonitor
            .ToList()
            .Where(x => x.Transito == "Respondida")
            .Select(x => new qryMonitor
            {
                Nsu = x.Nsu,
                Transito = x.Transito,
                NomeDaSolicitacao = x.NomeDaSolicitacao,
                NomeAutor = x.NomeAutor,
                Prioridade = x.Prioridade,
                DataSolicitacao = x.DataSolicitacao
            })
    };
        return View(viewModel);
}

and finally the view, created via wizard

@model IEnumerable<ServiceDesk.ViewModel.ChamadosViewModel>
@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
@using (Html.BeginForm())
{
    <p>
        @Html.ActionLink("Create New", "Create")
    </p>
    <table>
        <tr>
            <th></th>
        </tr>

        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ })     |
                    @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey     */ }) |
                    @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey     */ })
                </td>
            </tr>
        }
    </table>
}

When i ran those, i get a type mismatch (wich i’m able to comprehend, but not to solve). The complete massage is

"The model item passed into the dictionary is of type'ServiceDesk.ViewModel.ChamadosViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[ServiceDesk.ViewModel.ChamadosViewModel]'."

I looked for some similar topics on the web… i found few, but i was not able to solve the problem by comparing the examples and the above situation.

One thing i noted is that usually at samples, i saw code like
“Model.ForeachData”

and in my case intelisense gets nothing besides the model itself (looks like a group of a group of things and not just like a simple group).

Thanks in advance and sorry for my english (not my main language). Thanks againg for the help.

  • 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-13T05:34:02+00:00Added an answer on June 13, 2026 at 5:34 am

    The model you are passing to your view contains a collection, but you are attempting to iterate directly over the model.

    Change your view code to use the Chamados property.

    @foreach (var item in Model.Chamados)
    

    Then, change your model type in your view:

    @model ServiceDesk.ViewModel.ChamadosViewModel
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a question related to getting Drupal CCK fields (just in case that
This is a rather broad question, but I'm a beginner-intermediate programmer that has just
Another question related to this one . I have a List<SortableObjects> that is the
I'm just starting out with Paypal, so this is a newbie question. I've been
This is somewhat related to my previous question but I've realised that I needed
I've got a question related to a beginner Python snippet I've written to introduce
I faced this puzzle question[ related to data structure ] in a coding competition.
I have a question related to this one . I don't want to do
I'm a beginner in Android development but not in programming itself. Anyway, this question
First off, I'm sure this is a simple question. I'm just getting started 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.