We help IT Professionals succeed at work.
Get Started

MVC 5 Routing Question

123 Views
Last Modified: 2015-07-05
I am an MVC newbie

I have a controller that feeds from a view  I am using route attributes

View Index


The categories and documents are read from a database that is generate in another view

@foreach (var item in Model.ArticleList)
{
         <a href="/Article/@item.Category/@item.document">Read More...</a>
}

-------------- Controller ------------------------- with route attributes

        [Route("Article/{Category}/{Document}")]
        public ActionResult  Article(String Category, String Document)
        {                
            ..... Read data in ...............
            ...... get data from model for  Article To Display
            ..........................................
            return View(Model  ArticleToDisplay);
        }


I have dozens of categories and hundreds of documents and the categories are growing in the database

I need one view that I can pass the values and display it. There is no way I can physically create a view for each controller.

Lets say one of the categories is RootCauseAnalysis and a document is Equipment-Operators-Improve-Reliability  what I get is

The view 'Article/RootCauseAnalysis/Equipment-Operators-Improve-Reliability' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Article/Article/RootCauseAnalysis/Equipment-Operators-Improve-Reliability.aspx
~/Views/Article/Article/RootCauseAnalysis/Equipment-Operators-Improve-Reliability.ascx
~/Views/Shared/Article/RootCauseAnalysis/Equipment-Operators-Improve-Reliability.aspx


How can I get around not making a view for each category???


Thanks
Comment
Watch Question
The More I know, the more I don't know
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE