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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:34:03+00:00 2026-05-16T16:34:03+00:00

I am just getting into .NET MVC2 (.NET in general even) and I am

  • 0

I am just getting into .NET MVC2 (.NET in general even) and I am having a hard time getting familiar with the “flow” of things. The MVC framework, I get.. for the most part. The part that I am getting tripped up on is applying standard programming practices to .NET MVC.

For example

public ActionResult Index()
{
   var dataContext = new SiteContentDataContext();
   var data = from c in dataContext.SiteContents where c.Slug == "home-page" select c;
   // call/return getMainNav()
   // call/return getSubNav()
   return View(data);
}

public ActionResult SiteContent(string strSlug)
{
   var dataContext = new SiteContentDataContext();
   var data = from c in dataContext.SiteContents where c.Slug == strSlug select c;
   // call/return getMainNav()
   // call/return getSubNav()
   return View(data);
}

private void getSubNav()
{
   // get subnav records from db.
   // return subnav records.
}

private void getMainNav()
{
   // get main nav records from db.
   // return main nav records.
}

The Index and SiteContent view are identical except for the fact that the Index view uses a different master page. Both views have a subnav and a main nav that will be dynamic content from a database.

The question, finally, is how would I go about populating the getSubNav and getMainNav functions and second, how would I return that data to the view properly?

  • 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-16T16:34:03+00:00Added an answer on May 16, 2026 at 4:34 pm

    Look into ViewModel objects, objects you create whose purpose in life is to carry data to and from your Views. The Models folder created for you by default in a new MVC project would hold exactly those classes.

    You have options besides the ViewModel object methodology, but none are as clean. (The ViewData dictionary is around to help but it’s not intended to be the primary means of providing data to your views.) Here’s an example of how to set the Model property of the ViewData object to an instantiated, populated viewmodel instance:

        public ActionResult SiteContent(string strSlug) {
            SiteContentVM model = new SiteContentVM();
            SiteService siteService = new SiteService();
            model.Slug = siteService.GetALittleSlimyCreature(strSlug);
            model.List1 = siteService.GetList1();
            model.List2 = siteService.GetList2();
            ViewData.Model = model;
            return View();
        }
    

    You can now create a strongly typed view (complete with intellisense) to reference any properties of your ViewModel object instance from within your view simply through the Model property:

    <% foreach (var item in Model.List1) { %>
        <% Html.Encode(item.StringField) %> <!-- <= writing a property -->
        <% Html.RenderPartial("PartialNameHere", item); %> <!-- <= the equivalent of a usercontrol -->
    <% } %>
    

    As you see above the process of getting data from the database does not change for MVC. You do it just as you would in a normal webforms project. (…usually this involves instantiating a business logic or service class of some sort rather than actually writing the code in the MVC project.)

    Enjoy MVC!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just getting into ASP.NET Been avoiding it for years as I'm a desktop
I am just getting into ibatis with SqlMap for the first time and I
I'm just getting into creating some WCF services, but I have a requirement to
I'm just getting into unit testing, and have written some short tests to check
I'm just getting into the practice of version control (I'd like to use Eclipse
My little brother is just getting into programming, and for his Science Fair project,
I just started getting into BizTalk at work and would love to keep using
I have just been getting into low level programming (reading/writing to memory that sort
I'm just getting back into C++ after a couple of years of doing a
Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me.

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.