Asp.net mvc 局部视图和剖面图

Asp.net mvc 局部视图和剖面图,asp.net-mvc,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="pa

我有一个局部视图,将显示一个面板和一些文本,如下所示

<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>

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

使用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>

可以在局部视图本身中使用ViewBag。考虑下面的片段

@{ ViewBag.Text=Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是印刷行业的标准虚拟文本,当时一位不知名的印刷商拿起一个打印工具,争先恐后地制作了一本打字样本书。它不仅存活了五个世纪,而且还跨越到了电子排版,重新印刷maining基本上没有改变。它在20世纪60年代随着包含Lorem Ipsum段落的Letraset表单的发布而流行,最近又随着包括Lorem Ipsum版本在内的Aldus PageMaker等桌面出版软件的发布而流行。; } 信息 @文本
这是一种方法谢谢,是否可以直接在视图中而不是在控制器中执行此操作?是的,您可以在视图中执行此操作:@{ViewBag.DivText=Lorem Ipsum只是印刷和排版行业的虚拟文本。Lorem..;}