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?

4

2 回答 2

1

局部视图的典型例子是面包屑本身。例如,在您的控制器中,您可以拥有

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

因此,您的部分视图将如下所示:

@{
    ViewBag.Title = "Article";
}

<h2>Viewing Article @ViewBag.parentid >> @ViewBag.id</h2>
于 2013-02-14T18:04:40.193 回答
0

您可以使用部分视图或显示模板。您的控制器应该只构建将传递给视图的模型,然后在视图内您可以使用显示模板,该模板将基于模型构建所需的输出。

于 2013-02-14T17:59:59.047 回答