Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET MVC App - trouble getting data

Posted on 2011-09-04
5
Medium Priority
?
417 Views
Last Modified: 2012-05-12
Hey there,

Not sure exactly the best way to approach this because I don't really know what I'm doing but, I guess that's why I'm here!  :)

Anyway - I have created an ASP.NET MVC 2 Web Application in Visual Studio 2010.  I'm trying to get a working version of the DHTMLXScheduler component on my page using the tutorial located HERE.  The tutorial is in C# but my application has to be in VB (I'll be working with another programmer after he gets back from vacation so I'm trying to pull the load for two weeks).  

So, I have taken the .cs specific bits and translated them using THIS which seems to have worked fairly well because I can get the calendar displayed on my Index.aspx view.  So the first part of the tutorial is working for me.  I've got the view displaying the calendar.

The trouble comes in step 2 which involves getting data to display in the calendar.  To describe the problem behavior - I run the application from the IDE and it starts to load the page but, I get a dialog box that has what looks like the contents of an asp.net server error page.  The following looks like the important bits (I have stripped out some of the tags that were in the dialog box to make it easier for you to read):

Compiler Error Message: </b>BC30451: &#39;foreach&#39; is not declared. It may be
inaccessible due to its protection level.

Source Error:

Line 1:  &lt;%@ Page Language=&quot;VB&quot; Inherits=&quot;System.Web.Mvc.ViewPage&quot; ContentType=&quot;text/xml&quot; %&gt;

Line 2:  &lt;data&gt;

&lt;% foreach (var myevent in Model) { %&gt;
Line 4:  &lt;event id=&quot;&lt;%=myevent.id%&gt;&quot;&gt;

Line 5:  &lt;start_date&gt;&lt;![CDATA[&lt;%= String.Format(&quot;{0:MM/dd/yyyy HH:mm}&quot;,myevent.start_date) %&gt;]]&gt;&lt;/start_date&gt;</pre></code>


So it looks like the problem is somewhere in Data.aspx which contains the following code:
<%@ Page Language="VB" Inherits="System.Web.Mvc.ViewPage" ContentType="text/xml" %>
<data>
<% foreach (var myevent in Model) { %>
<event id="<%=myevent.id%>">
<start_date><![CDATA[<%= String.Format("{0:MM/dd/yyyy HH:mm}",myevent.start_date) %>]]></start_date>
<end_date><![CDATA[<%= String.Format("{0:MM/dd/yyyy HH:mm}",myevent.end_date) %>]]></end_date>
<text><![CDATA[<%= myevent.text%>]]></text>
</event>
<% } %>
</data>

Open in new window


Any idea where I might have gone wrong?  From googling around I'm thinking I've left something out that the VB needs and C# doesn't but I wouldn't even begin to know what that is.  

There are a bunch of pieces to this and I'd be happy to post anything you might need.

Thanks in advance for any help.  

B
0
Comment
Question by:ttist25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 36

Accepted Solution

by:
Miguel Oz earned 2000 total points
ID: 36481633
I think the syntax is:
@For Each myevent In Model
   Dim currentEvent = myevent
then use currentEvent to load what ever html your are planning to do for example a link:
@Html.ActionLink("Select", "Index", New With {.id = currentEvent.Id})
Check: (vbhtml is different form cshtml)
http://code.msdn.microsoft.com/Introduction-to-MVC-3-10d1b098/sourcecode?fileId=41255&pathId=85012416
0
 
LVL 1

Author Comment

by:ttist25
ID: 36481928
Thanks mas!  

That got rid of the error.  No data is loading into the calendar but it's not throwing the error.  Here's what I have in Data.aspx now:

<%@ Page Language="VB" Inherits="System.Web.Mvc.ViewPage" ContentType="text/xml" %>
<data>
<%  For Each myevent In Model
        Dim currentEvent = myevent%>
<event id="<%=currentEvent.id%>">
<start_date><![CDATA[<%= String.Format("{0:MM/dd/yyyy HH:mm}",currentEvent.start_date) %>]]></start_date>
<end_date><![CDATA[<%= String.Format("{0:MM/dd/yyyy HH:mm}",currentEvent.end_date) %>]]></end_date>
<text><![CDATA[<%= currentEvent.text%>]]></text>
</event>
<%  Next%>
</data>

Open in new window


I need to stop looking at it for the night and check that link in the morning.  

Thanks a bunch.  That was a great help.  
0
 
LVL 1

Author Closing Comment

by:ttist25
ID: 36481946
Thanks again
0
 
LVL 1

Author Comment

by:ttist25
ID: 36485504
Ugh - I'm such an IDIOT!  Your solution fixed everything.  When I ran the application the calendar was defaulting to July 2010 instead of the current month so the dates I had added didn't show.  

Kick Kick Kick :P

Thanks again!
0
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 36486073
No problem, it always work for me to go away for a walk or have a break if I am stuck.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question