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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:07:16+00:00 2026-05-17T15:07:16+00:00

I have the following scenario: my website displays articles (inputted by an admin. like

  • 0

I have the following scenario: my website displays articles (inputted by an admin. like a blog).

So to view an article, the user is referred to Home/Articles/{article ID}.

However, the user selects which article to view from within the Articles.aspx view itself, using a jsTree list.

So I what I need to do is to be able to differentiate between two cases: the user is accessing a specific article, or he is simply trying to access the “main” articles page. I tried setting the “Articles” controller parameter as optional (int? id), but then I am having problems “using” the id value inside the controller.

What is the optimal manner to handle this scenario? Perhaps I simply need a better logic for checking whether or not an id parameter was supplied in the “url”?

I am trying to avoid using two views/controllers, simply out of code-duplication reasons.

  • 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-17T15:07:17+00:00Added an answer on May 17, 2026 at 3:07 pm

    Use separate actions, like:

    public ActionResult Articles() ...
    public ActionResult Article(int id) ...
    

    Alternatively move it to an Articles controller (urls using the default route will be: Articles and Articles/Detail/{id}):

    public class ArticlesController : Controller
    {
        public ActionResult Index() ...
        public ActionResult Detail(int id) ...
    }
    

    If you still must use it like you posted, try one of these:

    public ActionResult Articles(int id = 0)
    {
         if(id == 0) {
             return View(GetArticlesSummaries());
         }
         return View("Article", GetArticle(id));
    }
    public ActionResult Articles(int? id)
    {
         if(id == null) {
             return View(GetArticlesSummaries());
         }
         return View("Article", GetArticle(id.Value));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following scenario: A user on one our customer's website clicks a
I have the following scenario. I have a PHP website witch contains about 3
I have the following scenario: The user has an on-site shopping cart where he
I have the following scenario I have a main form as MDI parent and
Due to company constraints out of my control, I have the following scenario: A
I want to accomplish the following scenario in Drupal: You have 2 content-types. Lets
How could I best implement the following scenario? I have a Next Period... button
Hi I need some help with the following scenario in php. I have a
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have the following scenario. I have created an ASP.NET web application (framework 3.5)

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.