1

I just watched the Pluralsight video on URL routing in ASP.NET MVC 3. I'm still a bit confused.

enter image description here

That image shows how my views are set up. I have a controller for each view. Perhaps I misunderstood something but when I did this I thought by adding the Portfolio view and controller instead of going to /home/portfolio it would just take me to /portfolio but it didn't. Now when I click on the portfolio link it takes me to /portfolio/portfolio.

Am I misunderstanding something about the way routing works in ASP.NET or am I just forgetting something?

3 Answers 3

3

It takes you to Portfolio/Portfolio because that is how you named the setup. The first one is the name of your controller (without controller in the name) PortfolioController. The second one is the name of your ActionResult, Portfolio which returns Portfolio.cshtml. If you wish to only see /Portfolio you could always have the PortfolioController use

public ActionResult Index(){ return View(); }

and then rename Portfolio.cshtml to Index.cshtml and you should be good to go.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok, that works now I just got to figure out how to change the ActionLink in the _Layout.cshtml to point to that new link because it's pointing to the old /Portfolio/Portfolio
1

when you have localhost/portfolio you that will call default action of portfolio which will be Index by default and you will see that view ,since you don't have view for that and you can make one you can access your portfolio action in your portfolio controller by /portfolio/portfolio

because it follows the default route which is in routConfig.cs in app_start folder

if you want to get the same result for /portfolio/portfolio just with /portfolio you can add a route like this in your routeconfig

 routes.MapRoute(
            name: "portfolio",
            url: "portfolio/{action}",
            defaults: new { Controller = "portfolio", Action = "portfolio" }
            );

be careful to write that before default route,because when it match the first route it would not check for other

sorry my English is not good

Comments

0

Rename the action and view to Index.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.