Click here to Skip to main content
15,885,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

Below is the class in my models
C#
public class LuceneSearchConfig
{
  public SearchResultObject getResults;

      public class SearchResultObject 
        {
            public Queue<List<string>> data { get; set; }
        }
}

---------------------------------
Below is my controller:
C#
test actionresult run()
{
  DCS.getResults = new LuceneSearchConfig.SearchResultObject();

DCS.getResults = DCS.SearchIndexWithTermQuery(xsearchtext, xtmmodel, 5);

 return PartialView("DocSearchResults", DCS.getResults);
}

---------------------------------
Below is my VIEW: (it won't open due to the wrong data type). Please see the error message below.)
HTML
@model IEnumerable<nowmvc.models.lucenesearchconfig.searchresultobject>

@foreach (var item in Model)
 {
// reading @item.data
}

Please help me how to send the correct type to the VIEW screen. Thank you.

What I have tried:

I tried to convert it to array but that won't work. I also tried casting "DCS.getResults" as IEnumerable and received errors below:

Quote:
The model item passed into the dictionary is of type 'System.Collections.Generic.Queue`1+Enumerator[System.Collections.Generic.List`1[System.String]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1
Posted
Updated 27-Feb-17 12:42pm
v2

1 solution

Here is a working mock of what you are trying to do:

1. Model
C#
using System.Collections.Generic;

namespace MvcQueue.Models
{
    public class DataModel
    {
        public Queue<List<string>> Data { get; set; } 
            = new Queue<List<string>>();
    }
}
2. Controller:
C#
using MvcQueue.Models;
using System.Collections.Generic;
using System.Web.Mvc;

namespace MvcQueue.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            var results = new DataModel();
            for (int i = 0; i < 10; i++)
            {
                results.Data.Enqueue(new List<string>() { "aaa", "bbb", "ccc" });
            }
            return View(results.Data);
        }
    }
}
3. View:
Razor
@{
    ViewBag.Title = "Queue Data Test";
}
<div>
    @foreach (var item in Model)
    {
        <p> data: 
        @string.Join(", ", item);
        </p>
    }
</div>
If you need to declare the Model in the view:
HTML
@Model = IEnumerable<List<string>>;
 
Share this answer
 
v2
Comments
blumonde - 28-Feb-17 8:59am    
Graeme, thank you. It works now.

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