查看:索引
@{
ViewBag.Title = "Home Page";
}
@section Content1
{
@Ajax.ActionLink("Just refresh", "_Test", "Home", null, new AjaxOptions() { UpdateTargetId = "ContentRefresh", HttpMethod = "Post" }, null)
@Html.Partial("_Test")
}
@section Content2
{
@Html.Partial("_Test2")
}
查看:_Test
@using (Ajax.BeginForm("_Test", "Home", null, new AjaxOptions(){UpdateTargetId = "ContentRefresh", HttpMethod = "Post" }, null))
{
@Html.TextBox("Name");
}
查看:_Test2
@ViewBag.Name: @ViewBag.DateTime
控制器:
public ActionResult _Test(FormCollection form)
{
string name = form["Name"];
if (Request.IsAjaxRequest())
{
Thread thread = new Thread(() => RunThread());
thread.Start();
ViewBag.Name = name == null ? "No one, just refreshing" : name;
ViewBag.DateTime = DateTime.Now.ToShortTimeString();
return PartialView("_Test2");
}
else
{
return View();
}
}
此事件是来自业务逻辑的调用 .
public void ChangeEventFromBusinessLogic(object o)
{
//event from RunThread....
//refresch my view
}
视图中的ajax调用确实有效 . 如何在没有任何用户操作的情况下从业务逻辑刷新视图 .
我怎么做的?