tags:

views:

32

answers:

1

Hey again, this question is mostly related to my previous question. I'm having an Edit view for my Product site to list the products with edit/delete link attached.. But how can I do:

/products/edit = show list with edit/delete links.

/products/edit/{productId} = show edit model (textboxes etc) for the specific product.

+2  A: 

You could always do this:

public ActionResult Edit(int? productId)
{
    if (productId != null)
    {
        return View("ViewWithTextBoxes.aspx");
    }
    return View("ViewWithEditDeleteLinks.aspx");
}

This being said, the case of showing edit and delete links doesn't seem like editing so I would recommend you using different action names. It seems more RESTful to me like this:

/products/index
/products/edit/{productId}

In this case you are having different actions and views for each case:

public ActionResult Index()
{
    var products = _repository.GetProducts();
    return View(products);
}

public ActionResult Edit(int productId)
{
    var product = _repository.GetProduct(productId);
    return View(product);
}
Darin Dimitrov
Indeed.. but I cant do it that way because /products/index = should display list of products without delete/edit links for the customer, and /products/edit = should display list of products with delete/edit links for the logged in admin.
ebb
I think that your design is wrong. `/products/index` should check whether the currently logged in user is admin and show the links respectively instead of having `/products/index` for normal users and `/products/edit` for admins.
Darin Dimitrov
Might be.. but I'm having a hard time to see how I can do /products/index and check whether the user is logged in and still keep all the management in a control panel.
ebb
Ah.. or I might just do as you say.. check for authentication at the Index controller and then render either IndexWithOutLoginor IndexWithLogin view?
ebb
Yes, that would be better.
Darin Dimitrov
Cool, thanks :)
ebb
Darin, sorry to bother you once again.. But how would I make it possible to both view the IndexWithOutLogin when I just visit the regular site while I'm logged in, but still render IndexWithLogin when I'm in the management panel? Like... http://something.com/products = show normal product page even if you are logged in. http://something.com/management/products (or something like that) shows the edit list for the product page when you're logged in.
ebb
How are you managing roles?
Darin Dimitrov
I'm using the Role attribute in my Controller, combined with authenticateRequest in my global.asax to hold the roles for each user updated.
ebb
Instead of having separate views, you can check if the user is logged in (or in a role with the correct permissions), and then display the edit links only inf the currently authenticated user is entitled to see those links.
Doozer1979