【发布时间】:2012-03-18 02:44:37
【问题描述】:
我是 MVC3 和 Razor 的新手。
我在母版页上有一个“注意横幅”作为部分视图,我想通过单击链接来“确认”以关闭横幅(无需重新加载页面)。我相信我需要使用 jQuery 和 Ajax 调用,但我似乎无法找到正确的组合。
这是我的 _Layout.cshtml 的一部分:
<section id="main">
<span id="attentionBar">@{ Html.RenderPartial("_AttentionBarPartial"); }</span>
@RenderBody()
</section>
这是我的部分视图(现在只是使用 Session 作为快捷方式来让它工作)。我不确定用什么作为“链接”来重新加载视图:
@{ this.Layout = null;}
@if(! String.IsNullOrWhiteSpace(@Session["Attention"].ToString()))
{
<div class="attentionPanel">
<span class="attentionLabel">Attention</span>
@Session["Attention"].ToString()
<span class="attentionLabel">
@* WHAT DO I PUT HERE *@
@Ajax.ActionLink("X", "AcknowledgeAttentionBar", "Home", new AjaxOptions{ UpdateTargetId="attentionPanel", InsertionMode=InsertionMode.Replace })
</span>
</div>
}
这是我的 Home 控制器。同样,我不确定代码是否完全正确,但基本上我会清除显示注意横幅的条件。
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Home Controller Updated At " + DateTime.Now.ToLongDateString()
+ " " + DateTime.Now.ToLongTimeString();
return View();
}
public PartialViewResult AcknowledgeAttentionBar()
{
Session["Attention"] = String.Empty;
return PartialView("_AttentionBarPartial");
}
}
【问题讨论】:
-
我还没有看到你的设计。但是,注意横幅很少是一个好的设计组件。
标签: asp.net asp.net-mvc-3 razor partial-views