0

i have created a area. after that i created the controller and then created the view as list. but the foreach statement is not able to recognize the Model. it is taking it as object but it should be an ienumarable? do i have to configure namespaces in the area somewhere?

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

<% foreach (var item in Model) { %>// error object doesn't contains the public method for geteumerator

casting the Model will solve the problem but it is not i want to do. everything is working fine outside the area

1 Answer 1

1

You can see that the other parts of the Inherits type are fully qualified. You must do the same with IEnumerable<>, which belongs in the System.Collections namespace:

 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage<System.Collections.IEnumerable<CentralBanking.Models.Currency>>" %>
Sign up to request clarification or add additional context in comments.

3 Comments

i was hoping to find out if i was missing some initial setting (if any)when configuring areas? so there is no special settings?
@mazharkaunainbaig: There is a <namespaces> tag under the <pages> section in Web.Config, which allows you to define namespaces that are automatically included for your views, but I don't know if that applies within the context of the Page directive. Try it out and let me know what happens.
thanks but the problem was version conflict . mine is a mvc2 product made in vs2010. i copied the v2.0 area's web.config into my new area's web.config inside vs2012. and everything is working fine

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.