[RESOLVED]return type of async function to return success msg

I have the following API controller:

public async Task<ActionResult> PostRegister(RegisterViewModel model)
        if (ModelState.IsValid)
            var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
                var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href="">link</a>");


//there should be a return value here

what I want is to return a success message that the user has been added how could that happen?

In the RegisterViewModel add a property for the result , set that property and return that viewmodel.

When you declare a method

async Task<ActionResult> MyMethod

The return type is ActionResult, the type declared in generic task. You can return any ActionResult you like, view, Json, file, etc.

Leave a Reply