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

  • Home
  • SEARCH
  • 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 5976585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:15:00+00:00 2026-05-22T21:15:00+00:00

I have the following structure: Controller.cs public ActionResult PageMain(string param) { return View(); }

  • 0

I have the following structure:

Controller.cs

public ActionResult PageMain(string param)
{
    return View();
}

PageMain.cs

namespace project1.Models
{
    public class PageMain
    {
        public DataTable dtable
        { 
             get {
                       // some code that returns a DataTable
             }
        }
     }
}

and finally in the view:

@using project1.Models
@model PageMain

var datatable = Model.dtable // but this is throwing an error since the model is null

Does anyone know why my model is returning null? How can I access the datatable in the PageMain.cs? I am new to MVC so if I have any logical error in the structure please do not hesitate in warning me 🙂

  • 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-22T21:15:00+00:00Added an answer on May 22, 2026 at 9:15 pm

    First, you need to set your logic to reach the database form your model. You could use ORM to achieve that.

    Then, pass your model to view from your controller. Assume that you have your person model like below:

    public class Person {
    
        public string Name {get;set;}
        public string SurName {get;set;}
        public int Age {get;set;}
    
    }
    

    In order to view specific Person data, you need to query your model and pass this model from you controller to your view:

    public ActionResult Index() {
    
      var _entities = new MyDataEntity();
      var model = _entities.Person;
      model = model.Where(x => x.Age > 20);
    
      return View(model);
    
    }
    

    The above controller is passing List of Person to your view. MyDataEntity class is your entity framework DataContext class.

    After that you need to put @model IEnumerable<Person> inside your model. Here is an example:

    @model IEnumerable<MyApp.Models.Person>
    
    <ul>
    @foreach(var item in Model){
    
      <li>Name : @item.Name</li>
      <li>Surname : @item.Surname</li>
      <li>Age : @item.Age</li>
    
    }
    
    </ul>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following structure: public class Dummy { public string Name { get;
I have the following structure public class MyClass : MyBaseClass<System.Int32> { } In a
Say I have the following models: public class Item { public int Id{ get;
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following structure: class Base { } class Child : Base {
I have the following classes (trimmed to only show the basic structure): public abstract
So we have a PHP+Zend Framework+Doctrine 1.2 application that has the following structure: Controller
I have following structure: class User < ActiveRecord::Base has_many :Hobbies, :dependent => :destroy accepts_nested_attributes_for
I have a code structure where there is base controller class providing the basic
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If

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.