62,046
社区成员
发帖
与我相关
我的任务
分享
public ActionResult Index(string Key)
{
if (Key == null)
Key = "top";
ViewData["topArt"] = db.Article.GetTopModel(Key); //获取一篇置顶文章
return View();
}
@{
Syd.Data.Article topArt = ViewData["topArt"] as Syd.Data.Article;
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "info";
}
@Html.Partial("/Views/Shared/top1.cshtml");
....省略无错的html....
<!--以下的代码,如果加载到页面,就会重复请求控制器,而且传参会丢-->
@{
if (topArt != null)
{
<div class="ny_r_2">
<img src="@topArt.ThumbImage" />
<div style="height: 142px; overflow: hidden;">
<p>
<span>@topArt.Title</span></p>
<p>
@topArt.Description</p>
</div>
<a href="/Channel/Info/@topArt.id" style="padding-left: 390px;">[阅读全文]</a>
</div>
}
}
@if (topArt != null)
{
<div class="ny_r_2">
<img src="@topArt.ThumbImage" />
<div style="height: 142px; overflow: hidden;">
<p>
<span>@topArt.Title</span></p>
<p>
@topArt.Description</p>
</div>
<a href="/Channel/Info/@topArt.id" style="padding-left: 390px;">[阅读全文]</a>
</div>
}