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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:39:38+00:00 2026-05-16T02:39:38+00:00

In the controller: public ActionResult Index() { ViewData[page] = 0; return View(data); } public

  • 0

In the controller:

public ActionResult Index()
{
    ViewData["page"] = 0;
    return View(data);
}

public ActionResult More(long page = 0)
{
    ViewData["page"] = page;
    return View(data);
}

So, I have two views: Index.aspx and More.aspx. I created a partial view (PartialView.ascx) that is used in both of the views. Inside the partial view, it accessed both Model and ViewData. The strange thing (to me anyway) is that when I tried to cast ViewData[“page”] to a long, I would get the following casting exception for one of the views:

System.InvalidCastException: Specified cast is not valid.

I tried to cast the ViewData[“page”] like the following:

if ((long) ViewData["page"] > 1) { ... }

and

long page = (long) ViewData["page"];
if (page > 1) { ... }

Each of them would throw a casting exception in one view of the other (but not both).

One difference between Index.aspx and More.aspx is that Index.aspx uses a master page, and More.aspx does not.

Would anyone have any suggestion what may be wrong? Please let me konw if I need to provide more details. BTW, I’m farily new to C# and ASP.NET MVC.

  • 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-16T02:39:38+00:00Added an answer on May 16, 2026 at 2:39 am

    This line:

    ViewData["page"] = 0;
    

    is setting the value to be a boxed int. You’re trying to unbox it to a long. The simplest way to avoid this is to box to a long to start with:

    ViewData["page"] = 0L;
    

    … or use int for your page number to start with. (Are you really going to get more than int.MaxValue pages?)

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You'll want to read the file line by line to… May 16, 2026 at 4:28 pm
  • Editorial Team
    Editorial Team added an answer I would use FTP. Use Apache FTP libraries. Client side:… May 16, 2026 at 4:28 pm
  • Editorial Team
    Editorial Team added an answer Why don't you delete the file in "serializeQuotes()" before writing… May 16, 2026 at 4:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have this code in my controller for Index view.. public ActionResult Index(int? id)
guy, i have a page in my asp.net mvc website. the Route configuration: public
I have the following code in my Site.Master page of an almost empty ASP.NET
I have a controller that is being called twice from an ActionLink call. My
I have a partial view (ascx) for displaying the top x articles of a
I have just installed the RTW 1.0 of the MVC framework. I was using
I am creating a modular ASP.NET MVC application using areas. In short, I have
I am rendering out a partial view like so: <div id=cart> <%Html.RenderPartial(Cart, Model); %>
I am receiving this error: The ViewData item that has the key 'DepartmentId' is
I don't think this should be in my view, but instead handled by the

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.