That's when, for example, I'm getting a user on the page. and sends a kind of welcome email to person. then it tells me:
ArgumentNullException: Value cannot be null. Parameter name: Email/NewPassword does not match any available view
It is the case that my registered user is in Account and when I send mail, it is in a folder at
Views/Email/NewPassword.
I have used the information contained here.
When I try to "call" the area that I would like to get hold of, I'll do it here. And This piece of code I use in my account controller.
var resultMail = await _viewRenderService.RenderToStringAsync("Email/NewPassword", viewModel);
var client = new SendGridClient(m.AzureName());
var from = new EmailAddress(m.MailFrom(), m.NameFromUsername());
var to = new EmailAddress(mail, UserValue.Navn);
var plainTextContent = Regex.Replace(resultMail, "<[^>]*>", "");
var msg = MailHelper.CreateSingleEmail(from, to, title, plainTextContent: plainTextContent,
var resulta = client.SendEmailAsync(msg);
In with - RenderToStringAsync
Where errors like happens there is where I have written "the error is here".
public async Task<string> RenderToStringAsync(string viewName, object model)
{
var httpContext = new DefaultHttpContext { RequestServices = _serviceProvider };
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
using (var sw = new StringWriter())
{
var viewResult = _razorViewEngine.FindView(actionContext, viewName, false);
if (viewResult.View == null)
{
throw new ArgumentNullException($"{viewName} does not match any available view");
}
var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary())
{
Model = model
};
var viewContext = new ViewContext(actionContext, viewResult.View, viewDictionary, new TempDataDictionary(actionContext.HttpContext, _tempDataProvider),
sw,
new HtmlHelperOptions()
);
await viewResult.View.RenderAsync(viewContext);
return sw.ToString();
}
}
What I have tried:
I've tried a part and I've tried that with GetView so you get the content I want to grab.