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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:32:24+00:00 2026-05-20T22:32:24+00:00

New to ASP.NET MVC (using MVC3 with Razor now) and I’m confused on passing

  • 0

New to ASP.NET MVC (using MVC3 with Razor now) and I’m confused on passing an object from the Controller to the View. Specifically, I’m experimenting with MVC3 and Rob Conery’s interesting Massive (http://blog.wekeroad.com/helpy-stuff/and-i-shall-call-it-massive). I’m messing with a blog as a simple web application to experiment with.

HomeController.cs:

public ActionResult Index()
        {
            var table = new DynamicModel("mydb", tableName: "Posts");
            //grab all the posts
            var posts = table.All();
            ViewData["Posts"] = posts;

            return View();
        }

This part works great. But how do I do this?

return View(posts);

If I reference @posts.PostID in the View, it errors out and says it’s not valid. So I tried creating a strongly typed view against the DynamicModel, but posts still wasn’t there.

I know I can create a ViewModel and type the view against that and plug my data in there. This is more about understanding how the Controller/View interact.

Thanks!

  • 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-05-20T22:32:25+00:00Added an answer on May 20, 2026 at 10:32 pm

    ASP NET MVC Templates is the solution.

    First of all, using ViewData is discouraged especially now in MVC 2.0 and 3.0 where there are many better ways to pass state to the view.

    Strongly typed view is the way to go. But What if you have a collection to pass? Well, you still can create a strongly typed view for the collection (or generic list) but standard solution is to use ASP NET MVC templates (which are ascx files) for the item and not the collection and call RenderPartial on your parent view:

    For example:

            <div>
                <% for (int i = 0; i < Model.Bars.Count; i++)
                   {%>
                <h3>
                    <a href="#">Bar
                        <%: String.Format("{0:g}", Model.Bars[i].DocumentDate.ToShortDateString())%></a></h3>
                <div>
                    <%: Html.DisplayFor(m => m.Bars[i].Content)%>
                </div>
                <%}%>
            </div>
    

    There is a very good series on this topic here.

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

Sidebar

Related Questions

Using the new ASP.NET MVC 3.0 Razor View Engine, is there any way to
I am using a Telerik MVC Batch editable grid with ASP.Net MVC3 Razor views.
I want to pass two values from controller action to asp.net MVC 3 Razor
I'm experimenting with an ASP.NET MVC 3 site, using razor as the view-engine. I
I've a web using asp.net MVC 3 with razor. In one view I'm having
I am programming using ASP.NET MVC 3 with Razor view engine. Here's what I'd
I am using jQuery and ASP.NET MVC 3 with the razor view engine .
Here's the situation: ASP.NET MVC 3 application using Razor as the view engine. Works
I am using Visual Studio 2010 / ASP.net MVC 3 with the Razor View
I am pretty new to asp.net MVC. I am using MVC3 and I was

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.