View: Index
@{
ViewBag.Title = "Home Page";
}
@section Content1
{
<div>
@Ajax.ActionLink("Just refresh", "_Test", "Home", null, new AjaxOptions() { UpdateTargetId = "ContentRefresh", HttpMethod = "Post" }, null)
</div>
@Html.Partial("_Test")
}
@section Content2
{
<div id="ContentRefresh">
@Html.Partial("_Test2")
</div>
}
View: _Test
@using (Ajax.BeginForm("_Test", "Home", null, new AjaxOptions(){UpdateTargetId = "ContentRefresh", HttpMethod = "Post" }, null))
{
@Html.TextBox("Name");
<input type="submit" value="Send name" />
}
View: _Test2
@ViewBag.Name: @ViewBag.DateTime
Controller:
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();
}
}
This event is call from business logic.
public void ChangeEventFromBusinessLogic(object o)
{
}
the ajax call from the view does work. how I refresh the view from Business logic without any user action.
how I do this?