我如何从业务逻辑中刷新局部视图 [英] how I refresh the partial view from Business logic

查看:80
本文介绍了我如何从业务逻辑中刷新局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看:索引

 @ {
ViewBag.Title =主页;
}

@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 >
}





查看:_Test

 @ using(Ajax.BeginForm (_ Test,Home,null,new AjaxOptions(){UpdateTargetId =ContentRefresh,HttpMethod =Post},null))
{
@ Html.TextBox(Name) ;
< 输入 < span class =code-attribute> type = submit value = 发送名称 / >
}





查看:_Test2

 @ ViewBag.Name:@ ViewBag.DateTime 





控制器:

  public  ActionResult _Test(FormCollection表单)
{
string name = form [< span class =code-string> 名称];

if (Request.IsAjaxRequest())
{
Thread thread = new Thread(()= > RunThread());
thread.Start();

ViewBag.Name = name == null 没有人,只需刷新:name;
ViewBag.DateTime = DateTime.Now.ToShortTimeString();

return PartialView( _Test2\" );
}
其他
{
返回查看( );
}
}





此事件是来自业务逻辑的调用。

< pre lang =cs> public void ChangeEventFromBusinessLogic( object o)来自RunThread的
{
// 事件....
// 刷新我的观点
}





来自视图的ajax调用确实有效。如何在没有任何用户操作的情况下从业务逻辑刷新视图。



我是怎么做到的?

解决方案

通过使用更新面板,您可以刷新您的部分页面





阅读本文


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)
{
      //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?

解决方案

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


read this


这篇关于我如何从业务逻辑中刷新局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆