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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:01:03+00:00 2026-05-26T22:01:03+00:00

I need show record from database. But I have a error: ‘object’ does not

  • 0

I need show record from database. But I have a error:

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

View:

 @using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Dodaj Pracownika</legend>

    @foreach (var pr in ViewBag.dane)
        {
            <div>Login: @pr.Login</div>

              <div>Imie: @pr.imie</div> 

        }
</fieldset>
}

Controller:

public ActionResult detail(int LoginID)
    {
        var user = (from p in baza.Logowanies
                    join d in baza.uzytkowniks on p.LoginID equals d.LoginID 
                    where LoginID == p.LoginID
                    select new { p.Login, p.Haslo, p.konto, d.imie, d.nazwisko, d.pesel, d.nip, d.telefon, d.adres_zamieszkania, d.email }).ToList();
        ViewBag.dane = user;
        return View();
    }

It was working when I put records from one table in database (without join in query). But now is something wrong.

Using

@grid.GetHtml

everything is allright.

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

EDIT

I make edits and now I have:

View:

@model Restauracja.Models.pracownikModel
 @foreach (dynamic pr in ViewBag.dane)
        {
            <div>Login: @pr.Login</div>

             <div>Imie: @pr.imie</div>

Model:

public class pracownikModel 
    {
         public LoginModel LoginModel { get; set; }
         public uzytkownikModel uzytkownikModle { get; set; }
       public pracownikModel() {
           LoginModel = new LoginModel();
           uzytkownikModle = new uzytkownikModel();
       }
    }

    public class LoginModel 
    {
        [Required]
        public string Użytkownik { get; set; }

        [Required]
        public string Hasło { get; set; }

        public string Konto { get; set; }

    }

    public class uzytkownikModel
    {
        [Required]
        public string imie { get; set; }

        [Required]
        public string nazwisko { get; set; }
           . . . . .

    }

And Controller:

public ActionResult Kontakt()
        {
            bazaDataContext baza = new bazaDataContext();
            var user = (from p in baza.Logowanies
                        join d in baza.uzytkowniks on p.LoginID equals d.LoginID
                        select new pracownikModel{p.Login, d.imie}).ToList();

            ViewBag.dane = user;
            return View(user);
        }

In controller in select I have

select new pracownikModel{p.Login, d.imie})

and I cant add

uzytkownik = p.Login, imie = d.imie

because insted uzytkownik and imie i have LoginModel or uzytkonikModel.

I have

select new pracownikModel{…}

and I have error:

Cannot initialize type ‘Restauracja.Models.pracownikModel’ with a collection initializer because it does not implement ‘System.Collections.IEnumerable’

  • 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-26T22:01:03+00:00Added an answer on May 26, 2026 at 10:01 pm

    You’ve changed to use an anonymous object so the view doesn’t know what type it is and defaults to the object type. You could use dynamic instead of var or you could select into a class with the same properties as the anonymous object in which case it would be able to determine the type and know that it had those properties.

        @foreach (dynamic pr in ViewBag.dane)
        {
            <div>Login: @pr.Login</div>
    
              <div>Imie: @pr.imie</div> 
    
        }
    

    Or

    public ActionResult detail(int LoginID)
    {
        var user = (from p in baza.Logowanies
                    join d in baza.uzytkowniks on p.LoginID equals d.LoginID 
                    where LoginID == p.LoginID
                    select new LoginModel
                    {
                        Login = p.Login,
                        Haslo = p.Haslo,
                        ...
                    }).ToList();
        ViewBag.dane = user;
        return View();
    }
    

    With the model class

    public class LoginModel
    {
          public string Login { get; set; }
          public string Haslo { get; set; }
          ...
    } 
    

    Any reason why you’re not using a view model rather than setting data on the ViewBag?

    Action

        ...
        return View( user );
    }
    

    View

    @model LoginModel
    
    ...
    
         @foreach (dynamic pr in Model)
         {
            <div>Login: @pr.Login</div>
    
             <div>Imie: @pr.imie</div> 
    
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make an image database which does not keep a consistent record
I want to show a random record from the database. I would like to
I have input from Form Name,Branch (text) x,y and Total are (number) fields Record
I have three tables in an SQL 2005 database, that I need to query
I'll be using the AdventureWorks Database to illustrate my problem. I need to show
I have cca 25 databases which I need to consolidate into 1 database. First
I have a website that grabs a random entry from a database and displays
Say I have a query that fetches [type][show_name]. For all [type]==5 records, I need
me again... I need show 10 or 20 or 50 results number of results
I need to show a screen or something, saying 'Loading' or whatever while long

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.