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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:35:58+00:00 2026-05-27T13:35:58+00:00

Using ASP.Net MVC3 with C#. Currently I am trying to pass a single database

  • 0

Using ASP.Net MVC3 with C#.

Currently I am trying to pass a single database record to my view page creating my own ad rotator.

Here is my controller code.

var rand = new Random((int) DateTime.Now.Ticks);
int numIterations = 0;
numIterations = rand.Next(1, 2);

CJAd cjad = db.CJAds.Single(c => c.category_id == 1 && c.ad_active == true && c.id == numIterations);

ViewData["SideBarAd"] = cjad;

Every code sample I have seen shows how to cycle through multiple records. How do I turn the ViewData on the view page into a database object and display it?

It tried this

@ViewData["SideBarAd"].ad_url

But received the error

CS1061: ‘object’ does not contain a definition for ‘ad_url’ and no extension method ‘ad_url’ accepting a first argument of type ‘object’ could be found (are you missing a using directive or an assembly reference?)

  • 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-27T13:35:59+00:00Added an answer on May 27, 2026 at 1:35 pm

    Why don’t you just include the CJAd in your view model? That’s much simpler.

    However, if you’re determined, use ViewBag instead, then you don’t need to cast.

    ViewBag.SideBarAd = cjad;
    

    in your view (assuming SideBarAd is a string that is the url to your ad)

    <img src="@ViewBag.SideBarAd"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a site using ASP.Net MVC3 with Razor. Inside the View/Shared folder,
I'm new to ASP.NET MVC. I'm currently using ASP.NET MVC 3. I'm trying to
I'm currently developing an app using ASP.NET MVC3 and Entity Framework 4.1 Code First
I'm building a new .NET 4.0 ASP.NET MVC3 application and currently the database is
I am currently programming a ASP.NET MVC3 application, using Entity Framework 4. There are
I'm currently using ASP.NET MVC3 RC and I'm using the unobtrusive JQuery validations as
I'm currently using ASP.NET MVC3 and MongoDB for a web app. MongoDB uses UTC
I'm currently using ValidationMessageFor to locate and display any errors in my asp.net MVC3
Currently I am using Amazon Cloudfront to service static objects on my ASP.Net MVC3
Using asp.net MVC I'd like to do this inside a view: <%= Html.TextBox(textbox1, null,

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.