PartialView和部分

时间:2014-11-19 16:39:05

标签: asp.net-mvc

我有一个局部视图,会显示一个面板和一些文字,如下所示..

<div class="panel panel-warning customHidden" id="infobox">
<div class="panel-heading"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> information</div>
<div class="panel-body well-sm">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>

我希望使用部分视图的视图传递此文本部分。我如何传递文本并在文本周围维护html div?

2 个答案:

答案 0 :(得分:0)

使用ViewBag元素。是动态对象。

ViewBag.DivText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem.."

然后..您可以在视图中使用@ ViewBag.DivText:

<div class="panel panel-warning customHidden" id="infobox">
<div class="panel-heading"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> information</div>
<div class="panel-body well-sm">@ViewBag.DivText</div>

答案 1 :(得分:0)

您可以在局部视图中使用(ViewBag)。请考虑以下代码段

@{
    ViewBag.Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
}

<div class="panel panel-warning customHidden" id="infobox">
<div class="panel-heading"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> information</div>
<div class="panel-body well-sm">
    @ViewBag.Text
</div>