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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:42:20+00:00 2026-06-16T11:42:20+00:00

Just Learning ASP.NET, VB.Net, MVC right now. My intention is to pass a model

  • 0

Just Learning ASP.NET, VB.Net, MVC right now.
My intention is to pass a model to a view.
I have successful test code for a simple string case.
Where I think I am stumbling today is in that the current viewmodel is a list of objects.
The error I get is “The model item passed into the dictionary is of type ‘MVC_Test1.Geocode_Google_Results[]’, but this dictionary requires a model item of type ‘MVC_Test1.Geocode_Google_Results’.”
So with my limited understanding, it appears that I am passing an object list(as intended) but the view model typeing is the simple object type that was used to create the list.

In a number of examples, the responses were in C#. These focused upon a For Each approach (which was my first notion of how to make this work).
I have tried this but ended up with object type errors in the For Each … AS object clause.

I found an www example which indicated that it should be approached as an array as in:
For I as integer = 0 to Model.Results.Count
This has allowed me to build the code but then results in the object type error mentioned above at runtime rather than at build.

Continueing reading, there are several topics which seem to invoke @model IEnumerable as an approach. This just makes the viewdata and model objects undefined when done as:

     @Modeltype IEnumberable MVC_Test1.Geocode_Google_Results

or

     @Model IEnumberable MVC_Test1.Geocode_Google_Results

I suspect that there is something simple/fundimental that I should know to make this all work. This just seems to straight forward of a design problem to not have a well constructed answer.

If the answer could be explained in the context of VB.net, It would be more helpful to me. I do use one of those web C# to VB.net converters to translate at times so any response is better than none.

Thanks,

Details below:

I have a simple class:

Public Class Geocode_Google_Results
    Public Property Results As New List(Of ManyGeocodeCoordinates)
    'Methods
    'Add to list
    Public Sub AddResults(Address, Latitude, Longitude)
        Results.Add(New ManyGeocodeCoordinates() With {.Address = Address, .latitude = Latitude, .longitude = Longitude})
    End Sub
End Class

Public Class ManyGeocodeCoordinates
     Public Property Address As String
     Public Property latitude As Double
     Public Property longitude As Double
End Class

I then populate with some data:

    For x As Integer = 1 To resultCount
        ManyResults(x) = New Geocode_Google_Results
        ManyResults(x).AddResults(results.Elements("result").Elements("formatted_address").Value, results.Elements("result").Elements("geometry").Elements("location").Elements("lat").Value, results.Elements("result").Elements("geometry").Elements("location").Elements("lng").Value)

    Next

I then pass along to the View:

    ElseIf resultCount = 1 Then
        ' Send the user to the results page...Default View Page
        Return View(ManyResults)

I then have a test view:

@Modeltype MVC_Test1.Geocode_Google_Results
@Code
    ViewData("Title") = "httptest"
End Code

<h2>httptest</h2>
Default single address view
@model.Results(0).Address   <br />
@model.results(0).latitude <br />
@model.results(0).longitude <br />

Upon running this in IE, I get the aformentioned error regarding the object list versus the object for the model type.

  • 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-16T11:42:21+00:00Added an answer on June 16, 2026 at 11:42 am

    After continued reading and experimenting here is what I found.

    A viewmodel (class) is a singular object. When I populated the instance of class with data, I did so using an array notation undoubtedly drawn from the object array context. However, the class is not an array of objects. This function was served by the property that was a list of objects.

    So assigning the data as Manyresults(x) was incorrect.

    The data needed to be assigned as

    ManyResults.AddResults(results.Elements("result").Elements("formatted_address").Value, results.Elements("result").Elements("geometry").Elements("location").Elements("lat").Value, results.Elements("result").Elements("geometry").Elements("location").Elements("lng").Value)
    

    Simlarly, in the view the model data is accessed with the form:

    @Model.Results(0).Address
    

    In my example, when multiple results are returned, the Model.Results(n).Address would be used where n is the result dimension that you are looking for. Model.results.count would be used to determine how many results there are in the view model.

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

Sidebar

Related Questions

Im new to asp.net mvc and just learning the basics right now. Im wondering
I have a simple ASP.NET MVC 3 dummy app (just learning MVC coming from
I have just started learning asp.net mvc and one reason of the primary reasons
i'm just learning to put in unit testing for my asp.net mvc when i
I have been learning ASP.NET MVC for a few months. I have learned about
I've never created a web page and I'm just learning ASP.NET now and all
I have been learning to develop websites using ASP.NET MVC 2 for work... and
I am learning Asp.net MVC 3. Just wondering, is there any way to define
I am just learning ASP.Net's MVC framework and so my question is likely basic.
I'm just starting out learning ASP.NET MVC. I'm working on a project created 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.