1

I've been learning MVC3 a bit for a while and although I understand most of the basics, the routing is something I just can't seem to get a hang off. I'm not sure whether I'm doing/thinking it in a correct way and the other answers I've read on stackoverflow/google only seem to confuse me more.

Anyway here's the situation. I've got a solution (cleaned it up for this question), where I'd like to create a structure in my views folder to organize everything in a structure I've been using for my asp.net webforms projects.

solution

Anyway, I was wondering whether it would be possible to get this kind of structure, where I could organize all my partial views into a specific subfolder called UserControls in which there are more subfolders where I would group every partial view I'd need for a specific page.

Ideally, my Views folder would contain 2 folders: Pages and UserControls and everything I'd need would go into a subfolder, or a sub sub folder.

Okay so if this is possible, how would I start routing this? I've been trying multiple ways of getting any result but they all end up in a 404 errors.

If this is a wrong approach of me, what would be a better alternative?

Thanks in advance!

4
  • Maybe providing us code will actually warrant an answer. Commented Oct 23, 2012 at 21:49
  • I don't want code, this is a mockup solution, I just want to know whether what I'm trying to do is possible and what would be a good approach to achieve this Commented Oct 23, 2012 at 21:52
  • You are ever so helpful. Good thing some people actually bothered to read it all. Good day. Commented Oct 23, 2012 at 22:24
  • You asked if you could use subfolders but the routing you put together kept giving you 404s. I then asked for your code. You denied that request. I prefer not to make assumptions at your approach, since you have tried something I would like to see what you're doing wrong instead of just spoon feeding you. Thanks. Commented Oct 23, 2012 at 22:45

2 Answers 2

1

Logically, this is better served by grouping your partials in with the actual views like so:

/Other
    /Partials
         OtherPartial1.cshtml
         OtherPartial2.cshtml
    Index.cshtml
/Some
    /Partials
         SomePartial.cshtml
    Index.cshtml
    SomeOtherView.cshtml

Now, you can certainly do as you suggest, but it simply means that your helpers in other views have more text to write to get where they want to go:

IE.

 @RenderPartial("Partials/OtherPartial.cshtml")

VS

 @RenderPartial("~/Views/PartialControls/Other/OtherPartial.cshtml")
Sign up to request clarification or add additional context in comments.

Comments

1

You could manually return the view file for each actionresult or partialactionresult.

I'd also recommend changing "UserControls (PartialViews)" folder to just PartialViews.

e.g.

public PartialViewResult OtherPartialView1()
    {
        return PartialView("../PartialViews/OtherViews/OtherPartialView.cshtml");
    }

Comments

Your Answer

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