My assumption after reading through the documentation was that we could use @Html.Action("ActionName", "ControllerName") to call an action method in a controller from a view.

Is that a false assumption? Because if my logic/assumption is wrong to begin with it would be helpful to know.

I have the following code in my HomeController.cs

public async Task<ActionResult> DidItWork()
        var dash = "dash equals nash";

        var manager = HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
        var user = new ApplicationUser { UserName = "test2 username2", Email = "" };
        var result = await manager.CreateAsync(user, "passwordGoesHere1!");
        if (result.Succeeded)
            await manager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account");

            return View();

        return View();    

And I have the following script in my _Layout.cshtml

    @*script for someone who presses the send/email button*@ 
        $("#sendButton").click(function () {
            alert("Handler for .click() called.");
            @Html.Action("DidItWork", "Home")

Upon starting up the program, and during debugging, DidItWork() appears to be called without ever clicking the #sendButton -- why is that?

When stepping through, everything appears to work as long the user name and email are unique. However, at the end, once it is done, it goes to the @Html.Action("DidItWork", "Home") line and throws an exception.

Thoughts/suggestions for fixing this? The exception info is below:

An exception of type 'System.Web.HttpException' occurred in System.Web.dll but was not handled in user code Additional information: Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'. Inner Exception: {"The view 'DidItWork' or its master was not found or no view engine supports the searched locations. The following locations were searched:..."}

Related posts

Recent Viewed