Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
Does it is possible to make some folder system controller and view..?
Hi,
I did as you said, but still not working..
again I am repeating my structure..
Controllers
/Property
SearchPropertyController.cs ---> inside I have a method that is calles "Create()"

now my View structure is like this.
Views
/Property
/SearchProperty
Create.cshtml


now my routes like this

C#
routes.MapRoute(
                    name: "Search_Mapping",
                    url: "Property/SearchProperty/{controller}/{action}/{id}",
                    defaults: new { controller = "SearchProperty", action = "Create", id = UrlParameter.Optional }
                    );


and now I am calling like this

C#
@Html.ActionLink("Search", "Create", "SearchProperty")



I am not able to get any resolution..?

thank you,



Thank you,
-Jitendra Jadav.
Posted
Updated 15-Jun-13 7:00am
v2

Create a TestController in the Controllers folder
Create a Test folder in Views and Create a view in it
Have the custom route configured in RouteConfig.cs as below

C#
routes.MapRoute(
                name: "TestRoute",
                url: "Folder1/Folder2/Test/{action}/{id}",
                defaults: new { controller = "Test", action = "GetAllSearchResult", id = UrlParameter.Optional }
            );



So when you try the following url (route)

{root}/Folder1/Folder2/Test


GetAllSearchResult action will be triggered and corresponding view will be rendered

You donot have to create folder within folder in the controllers to have a custom route. A custom route can be configured in the RouteConfig.cs.

hope it helps!
 
Share this answer
 
Comments
Jitendra.Jadav 15-Jun-13 12:58pm    
Hi,
I did as you said, but still not working..
again I am repeating my structure..
Controllers
/Property
SearchPropertyController.cs ---> inside I have a method that is calles "Creaet()"

now my View structure is like this.
Views
/Property
/SearchProperty
Create.cshtml


now my routes like this

routes.MapRoute(
name: "Search_Mapping",
url: "Property/SearchProperty/{controller}/{action}/{id}",
defaults: new { controller = "SearchProperty", action = "Create", id = UrlParameter.Optional }
);

and now I am calling like this

@Html.ActionLink("Search", "Create", "SearchProperty")


I am not able to get any resolution..?

thank you,
John-ph 15-Jun-13 14:53pm    
get the correct route in your config and try having the following structure in Views
Views/SearchProperty/Create.cshtml

For controller it is fine. MVC automatically identifies the controllers within folder.
Alternate, You can consider looking into creating and registering Areas in MVC 4.
MVC Areas with example[^]
 
Share this answer
 
Your route configuration is wrong for the above case. It should be
C#
routes.MapRoute(
               name: "Search_Mapping",
               url: "Property/{controller}/{action}/{id}",
               defaults: new { controller = "SearchProperty", action = "Create", id = UrlParameter.Optional });
 
Share this answer
 
Comments
Jitendra.Jadav 16-Jun-13 0:31am    
Hi,
I did same you told then I get error into _Layout.cshtml where I had given a @Html.RouteLink("Search", "Create", "SearchProperty")
error is like..

"A route named 'Create' could not be found in the route collection.
Parameter name: name"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900