[英]ASP.NET CORE MVC | System.ArgumentNullException : 'Value cannot be null. ' | Configuration.GetConnectionString
[英]System.ArgumentNullException: Value cannot be null ASP.NET MVC5
我有一個貸款申請表,它被設置為自動將用戶注冊為ApplicationUser
。 (它更像是注冊控制器的擴展版本)。 我已經調試過,但仍然得到System.ArgumentNullException: Value cannot be null
錯誤,它指向BaseController (return base.BeginExecuteCore(callback, state))
基本控制器
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
}
CheckRateController內部繼承自 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);
}
}
這是錯誤的屏幕截圖: https://prnt.sc/sv0rx7
查看堆棧跟蹤,這很明顯:
System.ComponentModel.DataAnnotation.ValidationContext.set_DisplayName(String Value)
我認為可能發生的是,您正在使用具有空名稱的DisplayAttribute
。
([DisplayAttribute(Name="")]
這將需要更改,因此它包含一些文本甚至只是間距。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.