Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 相当于MVC中的silverlight总线指示器_C#_Asp.net Mvc_Silverlight_Mvvm - Fatal编程技术网

C# 相当于MVC中的silverlight总线指示器

C# 相当于MVC中的silverlight总线指示器,c#,asp.net-mvc,silverlight,mvvm,C#,Asp.net Mvc,Silverlight,Mvvm,例如,在silverlight和MVVM中,我可以启动忙碌指示器 public class ViewModelBase : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged(string propertyName) { i

例如,在silverlight和MVVM中,我可以启动忙碌指示器

    public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private bool _isBusy;
        public bool IsBusy 
        {
            get
            {
                return _isBusy;
            }
            set
            {
                _isBusy = value;
                RaisePropertyChanged("IsBusy");
            }
        }


      ObervableCollection<OperationBase> _pendingOperations = new ObervableCollection<OperationBase>();
      public ViewModelBase()
      {

         _pendingOperations.CollectionChanged +=(s,e)=>
        {
            if( _pendingOperations.Count > 0)
               IsBusy = true // has operation going on
            else 
              IsBusy = false; //no operation

       }
  }

  void LoadData()
 {

    LoadOperation op = Context.Load(YourQuery, lo=>
    {
      _pendingOperations.Remove(lo); // lo is the operation, remove it 
      if (lo.HasError)
      {
            lo.MarkErrorAsHandled();
                MessageBox.Show(lo.Error.Message);
      }

    });

   _pendingOperations.Add(op);// add operation to the collection

 }

 void SaveData()
  {
       SubmitOperation so = this.context.SubmitChanges(s =>
       {

           _pendingOperations.Remove(s);                    

            if (s.HasError)
            {
                 s.MarkErrorAsHandled();
                 MessageBox.Show(s.Error.Message);
            }
        }, null);

       _pendingOperations.Add(so);// add operation to the collection }
    }

...

}
公共类ViewModelBase:INotifyPropertyChanged
{
公共事件属性更改事件处理程序属性更改;
受保护的void RaisePropertyChanged(字符串propertyName)
{
if(PropertyChanged!=null)
{
PropertyChanged(这是新的PropertyChangedEventArgs(propertyName));
}
}
私人厕所很忙;
公共图书馆很忙
{
得到
{
返回-您很忙;
}
设置
{
_isBusy=值;
RaisePropertyChanged(“IsBusy”);
}
}
ObervableCollection _pendingOperations=新建ObervableCollection();
公共ViewModelBase()
{
_pendingOperations.CollectionChanged+=(s,e)=>
{
如果(_pendingOperations.Count>0)
IsBusy=true//正在进行操作
其他的
IsBusy=false;//无操作
}
}
void LoadData()
{
LoadOperation op=Context.Load(您的查询,lo=>
{
_pendingOperations.Remove(lo);//lo是操作,请将其删除
如果(lo.HasError)
{
lo.MarkErrorAsHandled();
MessageBox.Show(lo.Error.Message);
}
});
_pendingOperations.Add(op);//将操作添加到集合
}
void SaveData()
{
SubmitOperation so=this.context.SubmitChanges(s=>
{
_挂起操作。移除;
如果(s.HasError)
{
s、 MarkErrorAsHandled();
MessageBox.Show(s.Error.Message);
}
},空);
_pendingOperations.Add(so);//将操作添加到集合}
}
...
}

我想在MVC中也这样做,任何关于如何实现这一点的想法,例如在搜索、创建或任何长过程中,我需要显示忙碌指示器并在最后关闭它,我知道没有任何属性更改,我想知道是否有任何方法可以假定你指的是MVC->ASP.NET MVC或基于HTML/Javascript的东西,带有某种web服务器组件

通常,在等待长时间运行的操作时,您会有一个动画gif(例如旋转的轮子),并显示和隐藏它们

在Javascript中,您可以利用承诺或使用通用回调函数

    //pseudo code
    loadData(function(data){
      // data came back async 
      // do something with data
     $('#loader').hide();
});

$('#loader').show();
还是有承诺

//method should return promise
var promise = loadData();
$('#loader').show();
promise.done(function(data){
  // do something with data
  $('#loader').hide();
});

当然,您也应该处理错误情况,但相同的原则适用于ASP.NET MVC中的…

?然后你需要用Javascript来做。你知道如何让它像busy indicatoram一样通用吗抱歉,但我没有弄明白我的逻辑在控制器类中这是在使用Javascript(jQuery)的客户端上。当你通过ajax向控制器请求时,你希望在显示加载索引器时得到部分更新。(与silverlight一样,它发生在客户端而不是服务器上)