0

I'm currently generating breadcrumbs on an object's Details page by calling a GetBreadcrumbs() method in the object's controller - in this method, the object's parent/grandparent are used to generate an unordered list. What's the best way to pull the HTML out of the controller to follow the Separation of Concerns paradigm? Should a partial view be used here?

2 Answers 2

1

Typical example of partial view is Breadcrum itself. For example, in your controller you can have

//
//GET: News/Article/x
public ActionResult Article(int id)
{
    //get parentid of article
    ViewBag.id = id;
    ViewBag.parentid;
    return View();
}

So, your partial view will be as below:

@{
    ViewBag.Title = "Article";
}

<h2>Viewing Article @ViewBag.parentid >> @ViewBag.id</h2>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. What if an Article has a parent Article, which may or may not have a parent Article, etc etc? Where would this logic of looping through the parents belong?
0

You could use partial views or display templates. Your controller should only build the model that will be passed to the view and then inside the view you could use a display template that will build the desired output based on the model.

1 Comment

Should this model (that I'm passing to the view) also include all of the parent objects that are required to build the breadcrumbs?

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.