DotVVM中的回发事件
在我的ViewModel中,我有以下代码:DotVVM中的回发事件,dotvvm,Dotvvm,在我的ViewModel中,我有以下代码: using System; using DotVVM.Framework.ViewModel; using DotVVM.Framework.Controls.Bootstrap; using APP_MIS_FACTURAS.DTO.Contoles; using System.Collections.Generic; using APP.Models.View; namespace APP.ViewModels { public cla
using System;
using DotVVM.Framework.ViewModel;
using DotVVM.Framework.Controls.Bootstrap;
using APP_MIS_FACTURAS.DTO.Contoles;
using System.Collections.Generic;
using APP.Models.View;
namespace APP.ViewModels
{
public class InicioViewModel : DotvvmViewModelBase
{
// Variables para la Vista
private InicioModel inicioModel = new InicioModel();
private bool constructor = true;
private SelectDTO[] inicializaLista;
// Mensaje 1
[Bind(Direction.ServerToClient)]
public string AlertText1 { get; set; }
[Bind(Direction.ServerToClient)]
public AlertType AlertType1 { get; set; }
public bool Dismissed1 { get; set; }
// Mensaje 2
[Bind(Direction.ServerToClient)]
public string AlertText2 { get; set; }
[Bind(Direction.ServerToClient)]
public AlertType AlertType2 { get; set; }
public bool Dismissed2 { get; set; }
// Mensaje 3
[Bind(Direction.ServerToClient)]
public string AlertText3 { get; set; }
[Bind(Direction.ServerToClient)]
public AlertType AlertType3 { get; set; }
public bool Dismissed3 { get; set; }
// Pagina Inicio
public string usuario { get; set; }
public string password { get; set; }
// Recuperar contrasena
public string correoElectronico { get; set; }
// Registro de usuario
public string nombre { get; set; }
public string apellidoPaterno { get; set; }
public string apellidoMaterno { get; set; }
public bool aceptoTerminos { get; set; }
public SelectDTO[] genero { get; set; }
public int selectGenero { get; set; } = 0;
public InicioViewModel()
{
if (constructor)
{
AutenticarAplicacion();
Limpiar();
inicializaLista = CargaCatalogoGenero();
constructor = false;
}
}
public void Limpiar()
{
//Clean Form Data
}
public void Autenticar()
{
// Operations to validate user
}
public void RegistroUsuario()
{
//Operations to create a user
}
private void AutenticarAplicacion()
{
//Operations to validate the status of the application
}
private SelectDTO[] CargaCatalogoGenero()
{
//Loading catalogs (Call database)
}
}
}
我有一个名为InicioViewModel()的构造函数。在这个函数中,我初始化了viewmodel中的变量,但我有一个问题,每次按下任何事件都会重新加载该函数。然后想检查是否可以在viewmodel内部捕获视图的回发事件。DotvvmViewModelBase类有多个方法可以重写-
Init
、Load
和PreRender
。您可以在中找到有关它们的详细信息
在示例中,将代码从构造函数移动到Load
方法,并使用Context.IsPostBack
代替constructor
私有字段。这将允许您区分初始页面加载和回发
请注意,如果您在页面中使用按钮并尝试在viewmodel上调用该方法,则该方法将在Load
方法之后执行。如果需要在viewmodel命令之后执行代码,则必须将其放在PreRender
方法中。请参见中的图表。请求管道与ASP.NET Web表单中的请求管道几乎相同