![](/img/trans.png)
[英]asp.net core Identity ConfirmEmailModel does not bind values correctly OnGetAsync
[英]ASP.NET Core debugging not working for OnGetAsync
我的頁面 model 調用了一個執行查詢的方法。
// Retrieve financials
var details = await (from detail in dbContext.StorageDetails
where (detail.ArrivalDate != null && detail.ArrivalDate <= dateRange.EndDate &&
(detail.DepartureDate == null || detail.DepartureDate >= dateRange.StartDate)) ||
(detail.TakeOrPayStartDate != null && detail.TakeOrPayStartDate <= dateRange.EndDate &&
(detail.TakeOrPayEndDate == null || detail.TakeOrPayEndDate >= dateRange.StartDate))
orderby detail.Location.City, detail.Location.State, detail.ArrivalDate
select new
{
Location = new
{
Id = detail.LocationId,
detail.Location.Name,
detail.Location.City,
detail.Location.State
},
detail.RailcarNumber,
detail.TakeOrPayId,
detail.TakeOrPayStartDate,
detail.TakeOrPayEndDate,
detail.ArrivalDate,
detail.DepartureDate,
detail.CherryPickDate,
detail.DailyStorageRate,
detail.SwitchInRate,
detail.SwitchOutRate,
detail.CherryPickRate,
detail.DailyStorageCost,
detail.SwitchInCost,
detail.SwitchOutCost,
detail.CherryPickCost,
})
.ToListAsync();
我在此查詢的開頭設置了一個斷點。 當我跨過它時,我的代碼在我的頁面的 CSHTML 文件中停止,並抱怨保留此查詢結果的變量是null
!
如果我沒有跳過此查詢,而是步入其中,我發現自己正在逐步完成ApplicationDbContact.OnModelCreating()
。
我認為OnModelCreating()
只是用於生成數據庫模式。 所以這對我來說根本沒有任何意義。
有沒有人可以在這里看到一些東西,或者我完全破壞了 ASP.NET 內核? 任何人將如何開始解決這樣的問題?
這是我的頁面 model 處理程序。 上面的查詢在helper.GetFinancialsByLocation()
中。
public async void OnGetAsync()
{
DateTime date = DateTime.Today;
DateRange = new DateRange
{
StartDate = new DateTime(date.Year, date.Month, 1),
};
DateRange.EndDate = DateRange.StartDate.AddMonths(1).AddMilliseconds(-1);
try
{
FinancialsHelper helper = new FinancialsHelper();
FinancialsLocations = await helper.GetFinancialsByLocation(DbContext, DateRange);
}
catch (Exception ex)
{
string s = ex.Message;
}
}
這是我的startup.cs。
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.