I have an Employee folder under Views, with a bunch of Views & Partial views - for edit/create/details and templates and its starting to get kinda messy...id like to create subfolders and move the related files there..
View
/Employee
Index.aspx
Edit.aspx
EditPartial1.ascx
EditPartial2.ascx
Details.aspx
DetailsPartial1.ascx
DetailsPartial2.ascx
Id like for it to look like
View
/Employee
Index.aspx
/Edit
Edit.aspx
EditPartial1.ascx
EditPartial2.ascx
/Details
Details.aspx
DetailsPartial1.ascx
DetailsPartial2.ascx
What do i do in the controllers to redirect this properly
public ActionResult Edit(int id)
{
//Do stuff for edit
return View("Edit", employee);
}
}
to something like this?
public ActionResult Edit(int id)
{
//Do stuff for edit
return RedirectToRoute("Edit", employee);
}
}
public ActionResult Edit(int id)
{
//Do stuff for edit
//put model in ViewData
ViewData["Model"]=model;
ViewData["GenericPartial"]="~/Views/Employee/Edit/EditPartial1.ascx"
return View("Generic");
}
}
public ActionResult Detail(int id)
{
//Do stuff for edit
//put model in ViewData
ViewData["Model"]=model;
ViewData["GenericPartial"]="~/Views/Employee/Detail/DetailPartial1.ascx"
return View("Generic");
}
}
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
Marked as answer by ricka6 on May 21, 2010 03:22 PM
Another option would be to create a simple View Engine to do this. Take a look at this example that deals with a similar issue. The author of the post shows how to set up a new view engine to look for views in different folders http://www.coderjournal.com/2009/05/creating-your-first-mvc-viewengine/
The only time you need to resort to fully qualified paths is if you want to break out of the default folder locations, but since everything is still under "~/Views/<controllername>", you're fine using the relative syntax.
Marked as answer by jerrolds on May 19, 2010 10:01 PM
Jerrolds
Member
95 Points
123 Posts
Cleaning up my views - moving aspx/templates to other folders?
May 19, 2010 04:21 PM|LINK
I have an Employee folder under Views, with a bunch of Views & Partial views - for edit/create/details and templates and its starting to get kinda messy...id like to create subfolders and move the related files there..
View
/Employee
Index.aspx
Edit.aspx
EditPartial1.ascx
EditPartial2.ascx
Details.aspx
DetailsPartial1.ascx
DetailsPartial2.ascx
Id like for it to look like
View
/Employee
Index.aspx
/Edit
Edit.aspx
EditPartial1.ascx
EditPartial2.ascx
/Details
Details.aspx
DetailsPartial1.ascx
DetailsPartial2.ascx
What do i do in the controllers to redirect this properly
public ActionResult Edit(int id) { //Do stuff for edit return View("Edit", employee); } } to something like this? public ActionResult Edit(int id) { //Do stuff for edit return RedirectToRoute("Edit", employee); } }imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Cleaning up my views - moving aspx/templates to other folders?
May 19, 2010 05:51 PM|LINK
You cannot do this because of the default View engine.Howevere there is awork around.
Create a simple view (say Generic.aspx),
<html>
<% Html.RenderPartial(ViewData["GenericPartial"].ToString(),ViewData["Model"]); %>
</html>
and return always Generic View
public ActionResult Edit(int id)
{
//Do stuff for edit
//put model in ViewData
ViewData["Model"]=model;
ViewData["GenericPartial"]="~/Views/Employee/Edit/EditPartial1.ascx"
return View("Generic");
}
}
public ActionResult Detail(int id)
{
//Do stuff for edit
//put model in ViewData
ViewData["Model"]=model;
ViewData["GenericPartial"]="~/Views/Employee/Detail/DetailPartial1.ascx"
return View("Generic");
}
}
Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Cleaning up my views - moving aspx/templates to other folders?
May 19, 2010 08:10 PM|LINK
Another option would be to create a simple View Engine to do this. Take a look at this example that deals with a similar issue. The author of the post shows how to set up a new view engine to look for views in different folders
http://www.coderjournal.com/2009/05/creating-your-first-mvc-viewengine/
Blog | Twitter : @Hattan
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: Cleaning up my views - moving aspx/templates to other folders?
May 19, 2010 08:40 PM|LINK
This will work:
return View("Edit/Edit", employee);
The only time you need to resort to fully qualified paths is if you want to break out of the default folder locations, but since everything is still under "~/Views/<controllername>", you're fine using the relative syntax.