|
|
|
| sn33zingpanda : On September 15, 2008 10:47 PM said: |
Trying to follow along with your vb code in C#. When I run the app for the first time, I get
Line 13: <% foreach (Call c in ViewData.Model)%>
CS1579: foreach statement cannot operate on variables of type 'object' because 'object' does not contain a public definition for 'GetEnumerator'
I've tried to remove my dbml and re-create it following your pattern. I have a Calls table that I have dropped onto my Call model.
Not sure if there's a difference between C# and VB that's biting me here, or if I'm simply missing a step.
Good video overall... high quality video and audio, good presentation.
|
|
|
| swalther : On September 16, 2008 2:29 PM said: |
@sn33zingpanda -- Yes, this is a difference between C# and VB.NET. In C#, you must explicitly cast ViewData.Model to an IEnumerable in your foreach loop:
<% foreach (var c in (IEnumerable)ViewData.Model) { %>
The other option is to use a strongly typed view. When you create a strongly-typed view, you specify the type of the ViewData.Model property in your code-behind class.
|
|
|
|
|
| sboys : On October 22, 2008 7:00 AM said: |
I am trying to add a Mvc View user control as shown in the video but the code in the Index.aspx page is failing on the RenderUserControl line.
<% foreach (Project p in (IEnumerable)ViewData.Model)
{ %>
<%= Html.RenderUserControl (ViewData.Model, "~/Views/Home/ProjectTemplate.ascx", p); %>
<% } %>
The error message is 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RenderUserControl' and no extension method 'RenderUserControl' acceptin a first argument of type 'System.Web.Mvc.HtmlHelper' could be found.
I have the following in the Index.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcCorporate.Models;
namespace MvcCorporate.Views.Home
{
public partial class Index : ViewPage
{
}
}
How do I get access to the RenderUserControl?
|
|
|
| fchalip : On October 22, 2008 8:13 PM said: |
How about displaying 2 tables in the View.
Let say we want to display 2 different LinkToSql Queries (Top 5 New Releases and Movies directed by Steven Spielberg)
How we do that if return View on the Controller only accepts one Model object?
Francisco
|
|
|
| mstum : On October 22, 2008 8:17 PM said: |
Thank you! I'm even going to overlook that "Star Wars II" mistake you did in the movie table :P Good work on the videos, they rock!
|
|
|
| anthonywjones66 : On November 16, 2008 3:53 PM said: |
Preview 5 is now using Html.RenderPartial instead of RenderUserControl
|
|
Leave a Comment
You must be logged in to leave a comment. Click here to log in.