Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
View: Index
Razor
@{
    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
HTML
@using (Ajax.BeginForm("_Test", "Home", null, new AjaxOptions(){UpdateTargetId = "ContentRefresh", HttpMethod = "Post" }, null))
    {  
        @Html.TextBox("Name"); 
        <input type="submit" value="Send name" /> 
    }


View: _Test2
HTML
@ViewBag.Name:  @ViewBag.DateTime 


Controller:
C#
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.
C#
public void ChangeEventFromBusinessLogic(object o)
{
      //event from RunThread....
      //refresch my view
}


the ajax call from the view does work. how I refresh the view from Business logic without any user action.

how I do this?
Posted
Updated 18-Nov-13 23:39pm
v5
Comments
Sampath Lokuge 18-Nov-13 6:59am    
What happened when you run above code ? Can we have more info ?

1 solution

by using the update panel ,you can refresh your partial page


read this
 
Share this answer
 
v3
Comments
Member 10294696 19-Nov-13 5:31am    
ok, how I call it from my controller...

please give me working code? :-)

I'm a newbie
King Fisher 19-Nov-13 5:49am    
i have updated,checkout
King Fisher 19-Nov-13 5:47am    
r u working in 3 tier

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900