0

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.

0

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

7 Comments

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.
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.
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.
Ah.. or I might just do as you say.. check for authentication at the Index controller and then render either IndexWithOutLoginor IndexWithLogin view?
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... something.com/products = show normal product page even if you are logged in. something.com/management/products (or something like that) shows the edit list for the product page when you're logged in.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.