asp.net mvc - Are nested views in MVC possible? -


i experimenting mvc, attempting make example stock control panel teach myself basics of working mvc , entity framework.

i have database 2 tables, categories & products. on mvc site want able browse rows in these tables, categories share 1 many relationship products.

i have set can view/edit/delete categories in mvc, want able view/edit/delete products within categories , not know how go it.

my current url structure goes <url>/categories follow accessing list of products within category navigating <url>/categories/<category id>/products display list of products associated category, , <url>/categories/<category id>/products/delete/<product id> etc manipulate them.

i've looked @ adding custom routes registerroutes function not think have understanding this, created

routes.maproute(     "products",// route name     "category/{categoryid}/{controller}/{action}/{id}",// url parameters     new { categoryid = "", controller = "products", action = "index", id = urlparameter.optional }  // parameter defaults ); 

which seems wrong, , have no idea how relationship betwen url ad default parameters work, or how links folder structure in project.

is attempting wrong? should there other way it? guidance appreciated.

typically have controller categories , products. categories controller

public class categoriescontroller : controller {      public actionresult index() {         return view(db.categories());     } 

this gives url of <url>/categories give list of categories.

then you'd have edit actionresult take categoryid , view details of category url <url>/categories/1

public actionresult edit(int id) {     var model = db.categories.find(id);     return view(model); } 

on edit screen show list of products associated category in table/grid whatever add edit , delete buttons/links. if add button/link clicked redirect products controller create action , pass categoryid in parameter. url <url>/products/create/1 , action

public actionresult create(int id) {     var model = new product(){ categoryid = id};     return view(model); } 

if clicked edit on product category edit view call edit action on product controller , pass productid in parameter. url <url>/products/edit/1 , action

public actionresult edit(int id) {     var model = new db.products.find(id)     return view(model); } 

everyone has preferences i've created pretty complex mvc sites without ever having modify default route or create new ones.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -