Reputation: 44
I have a Loan Application form, which is set to also automatically register the user as an ApplicationUser
automatically. (It's more like an extended version of the Register Controller). I have debugged and I still get System.ArgumentNullException: Value cannot be null
error which is pointing at a BaseController (return base.BeginExecuteCore(callback, state))
BaseController
public class BaseController : Controller
{
#region Protected Methods
protected override IAsyncResult BeginExecuteCore(AsyncCallback callback, object state)
{
string cultureName = RouteData.Values["culture"] as string;
// Attempt to read the culture cookie from Request
if (cultureName == null)
cultureName = Request.UserLanguages != null && Request.UserLanguages.Length > 0 ? Request.UserLanguages[0] : null; // obtain it from HTTP header AcceptLanguages
// Validate culture name
cultureName = CultureUtility.GetImplementedCulture(cultureName);
if (RouteData.Values["culture"] as string != cultureName)
{
// Force a valid culture in the URL
RouteData.Values["culture"] = cultureName.ToLowerInvariant(); // lower case too
Response.RedirectToRoute("Default", RouteData.Values); // Redirect user
}
// Modify current thread's cultures
Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(cultureName);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
return base.BeginExecuteCore(callback, state);
}
#endregion Protected Methods
}
Inside CheckRateController inheriting from BaseController
// POST: CheckRate/Index
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Index(CheckYourRateViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser
{
FirstName = model.FirstName,
LastName = model.LastName,
UserName = model.UserName,
PhoneNumber = model.Phone,
DateOfBirth = model.DateOfBirth,
State = model.State,
Street = model.Street,
City = model.City,
Country = model.Country,
YearlyIncome = model.IndividualYearlyIncome,
AdditionalYearlyIncome = model.AdditionalYearlyIncome,
IsAdmin = YesNo.No,
CashBalance = 0.00M,
IsBorrower = YesNo.Yes,
RegisteredDate = DateTime.Now,
EmploymentStatus = model.EmploymentStatus
};
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
return View(model);
}
private void AddErrors(IdentityResult result)
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
This is the screenshot of the Error: https://prnt.sc/sv0rx7
Upvotes: 1
Views: 178
Reputation: 11
Looking at the stack trace this stands out:
System.ComponentModel.DataAnnotation.ValidationContext.set_DisplayName(String Value)
What I think might be happening, is that you're using a DisplayAttribute
with an empty Name.
([DisplayAttribute(Name="")]
This will need changing so it contains some text or even just spacing.
Upvotes: 1