1

my question is strictly connected with this one ASP.NET MVC View throwing CS1061 error related to type of model object passed as ViewDdata to a view , but my reputation is to small to add a comment there and when I added my question as an 'answer' it was deleted... So please read the question (thread) mentioned above and the answer for it. I followed the steps suggested but it didn't work for me because of the following errors:

(I will post screenshots to show you both the code and the errors. The names of the variables etc. are changed in comparison to Howiecamp's code but the rest is the same because it's the same step in that tutorial.)

Ok so this is what happens when I have "ViewData" in "foreach" loop: screenshot 1

iIf I change it to "Model" like you instructed, suddenly Visual Studio doesn't understand the "foreach": screenshot 2

It does understand it if I put "IEnumerable" in the first line like you suggested, however after that it stops recognizing "Html.ActionLink": screenshot 3: edge.imgur.com/wcgtI.jpg (sorry, as a new user I can post only 2 hyperlinks :| )

What should I do in this case?

Community
  • 1
  • 1
Lord_Blizzard
  • 25
  • 2
  • 9
  • PLease, add the controller and model screenshot, i think problem is in them – Evgeniy Labunskiy May 24 '11 at 11:59
  • @evgeniy.labusnkiy Thank you for your reply. Here are screenshots you asked for: [SklepAlfaModel.dbml](http://edge.imgur.com/KIEDQ.jpg) [SklepAlfaModelDataContext.cs](http://edge.imgur.com/NOlFj.jpg) [ProduktyController.cs](http://edge.imgur.com/IwMWr.jpg) [Kategorie.aspx.cs](http://edge.imgur.com/tNS2g.jpg) - almost blank at this stage of the tutorial. Also please keep in mind that I'm following [this tutorial](http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx), and I'm a newbie so there can be some stupid mistake somewhere. I'm using VS2010 and MVC 3. – Lord_Blizzard May 24 '11 at 13:49

1 Answers1

0

Actually I found my answer in the comments of that article I was referring to at the beginning (I must had been blind not to see it...)

Sorry everyone for bothering you. But as I took some of your time than maybe I will give also the correct answer for this problem (which gave Benjamin Anderson and if I could I would give him reputation point which are so precious here :) ) so if anyone else followed that tutorial and stuck on the same stage he would find the answer here.

Apparently the cause of the problem was that Scott was using an older version of MVC at that time. So if you want this to work you have to:

1) Instead of "ViewData" put "Model"

Instead of

foreach (var kategoria in ViewData)

put

foreach (var kategoria in Model)

2) In the first line you have to add >

Instead of

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<SklepAlfa.Models.Kategorie_produktow>" %>

put

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<SklepAlfa.Models.Kategorie_produktow>>" %>

3) Alter your ActionLink definition!

Instead of

<%= Html.ActionLink(category.CategoryName, new { action="List", category=category.CategoryName }) %>

put

<%= Html.ActionLink(category.CategoryName, "List", new {category= category.CategoryName }) %>

That was the case.

Community
  • 1
  • 1
Lord_Blizzard
  • 25
  • 2
  • 9