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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:05:16+00:00 2026-05-18T08:05:16+00:00

I am having a small problem geting to some data within my MVC C#

  • 0

I am having a small problem geting to some data within my MVC C# application.

In the controller i have the following to retrieve a dataset to use in the View.

public ActionResult Franchisee()
    {
        getNav();

        var data = (
                   from f in DietCenterDB.Franchises
                   join fc in DietCenterDB.FranchiseContents on f.ID equals fc.FranchiseId
                   into ffc
                   from subffc in ffc.DefaultIfEmpty()
                   select new { 
                                State = f.State,
                                City = f.City,
                                AccountCode = f.AccountCode,
                                CenterNumber = f.CenterNumber, 
                                FranchiseContentId = (subffc == null ? 0 : subffc.FranchiseContentId) }
                    ).ToList();

        return View(data);
    }

The View has the following code

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Content.master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<dynamic>>" %>

<asp:Content ID="Head" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <h1>Franchisee Administration - <%: Html.ActionLink("Add New", "FranchiseeEdit", new { id = 0 }) %></h1>
    &raquo; <%: Html.ActionLink("Content Management Home", "Index") %>
    <p></p>
    <table cellpadding="0" cellspacing="0" width="600px">
        <%
            int counter = 0;
            string rowClass;

            foreach (var item in Model) {
                if ((counter % 2) == 0)
                {
                    rowClass = "r1";
                }
                else
                {
                    rowClass = "r2";
                }

                string dataString = item.State + " " + item.City + " " + item.AccountCode + " " + item.CenterNumber;

        %>

                <tr class="row <%: rowClass %>">
                    <td>
                         <%: Html.ActionLink(dataString, "FranchiseeEdit", new { id = item.ID, City = item.City, State = item.State, Zip = item.Zip })%>
                    </td>
                    <td align="right">
                         <%: Html.ActionLink("Edit Microsite Content", "MicrositeContentEdit", new { id = item.ID, City = item.City, State = item.State, Zip = item.Zip })%>
                    </td>
                </tr>


            <% counter++; %>
        <% } %>
   </table>


</asp:Content>

When I run the app i get the following error

‘object’ does not contain a definition for ‘State’

When debugging, the debugger shows that the data is in fact in memory.

Any tips or clues are greatly appreciated!!!

  • 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-18T08:05:17+00:00Added an answer on May 18, 2026 at 8:05 am

    I’d say it’s because you have a dynamic ViewPage, not a strongly-typed one:

    Inherits="System.Web.Mvc.ViewPage<IEnumerable<dynamic>>"
    

    Not saying its the problem, but will make things tricky.

    Why don’t you project your query into a ViewModel, and bind to that:

    var data = (
                       from f in DietCenterDB.Franchises
                       join fc in DietCenterDB.FranchiseContents on f.ID equals fc.FranchiseId
                       into ffc
                       from subffc in ffc.DefaultIfEmpty()
                       select new MyViewModel { 
                                    State = f.State,
                                    City = f.City,
                                    AccountCode = f.AccountCode,
                                    CenterNumber = f.CenterNumber, 
                                    FranchiseContentId = (subffc == null ? 0 : subffc.FranchiseContentId) }
                        ).ToList();
    

    And then in your View:

    Inherits="System.Web.Mvc.ViewPage<IEnumerable<MyViewModel>>"
    

    EDIT

    MyViewModel is a simple class you need to create, which allows lightweight storage for your model:

    public class MyViewModel
    {
       public int State {get;set;}
       public int City {get;set;}
       public int AccountCode {get;set;}
       public int CenterNumber {get;set;}
       public int FranchiseContentId {get;set;}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small Win32 console application which is essentially a test harness. I
I am having small problem in my JS where i need to iterate through
I am having some problems getting a small piece of text to be centered
I'm having some trouble getting this layout to work correctly in IE. The problem
Ok, I fear that this is just me having forgotten some small stupid thing
I’m currently working on a small web app that allows people to search for
Ive gotten some great help here and I am so close to solving my
One of the pages in our web application polls the server approximately every 10
I am learning the prototype framework and javascript in general and am tring to
Been a while since I've dealt with ASP.NET and this is the first time

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.