如何在CSHTML文件中使用ICommand

时间:2018-03-26 12:58:30

标签: html icommand

有人可以告诉我如何在WPF中调用ICOMMAND属性,但是在csHTML文件中。下面提供的代码是我的视图模型,我基本上需要能够调用或访问ICommand属性,基本上这是我在wpf中的方式,但在cshtml中我有点困惑。

/// <summary>
/// The View Model for a login screen
/// </summary>
public class LoginViewModel : BaseViewModel
{
    #region Public Properties

    /// <summary>
    /// The username of the user
    /// </summary>
    public string Username { get; set; }

    /// <summary>
    /// A flag indicating if the login command is running
    /// </summary>
    public bool LoginIsRunning { get; set; }

    #endregion

    #region Commands

    /// <summary>
    /// The command to login
    /// </summary>
    public ICommand LoginCommand { get; set; }

    #endregion

    #region Constructor

    /// <summary>
    /// Default constructor
    /// </summary>
    public LoginViewModel()
    {
        // Create commands
        LoginCommand = new RelayParameterizedCommand(async (parameter) => await LoginAsync(parameter));
    }

    #endregion

    /// <summary>
    /// Attempts to log the user in
    /// </summary>
    /// <param name="parameter">The <see cref="SecureString"/> passed in from the view for the users password</param>
    /// <returns></returns>
    public async Task LoginAsync(object parameter)
    {
        await RunCommandAsync(() => LoginIsRunning, async () =>
        {
            // Call the server and attempt to login with credentials
            // TODO: Move all URLs and API routes to static class in core
            // TODO: Fix password to use the passed in parameter instead

            var result = await WebRequests.PostAsync<ApiResponse<LoginResultApiModel>>(
                "http://localhost:5000/api/login",
                new LoginCredentialsApiModel
                {
                    Username = Username,
                    Password = "123456"
                });

            // TODO: Validate reponse

            // TODO: Redirect if response is valid
        });
    }
}

0 个答案:

没有答案