Ich muss in der Lage sein, die Anzahl der Unterschiede für die Geschäftstage zwischen zwei Daten zu berechnen: von DataSequestMade bis dateveriss . Ich habe diesen Code verwendet, den ich gefunden habe: < /p>
Ich muss in der Lage sein, die Anzahl der Unterschiede für die Geschäftstage zwischen zwei Daten zu berechnen: von DataSequestMade bis dateveriss . Ich habe diesen Code verwendet, den ich gefunden habe: < /p> [code]var calculatedBusinessDays = 1 + ((DateIssued - DateRequestMade).TotalDays * 5 - (DateRequestMade.DayOfWeek - DateIssued.DayOfWeek) * 2) / 7;
if (DateIssued.DayOfWeek == DayOfWeek.Saturday) calculatedBusinessDays--;
if (DateRequestMade.DayOfWeek == DayOfWeek.Sunday) calculatedBusinessDays--;
BusinessDays = (int)calculatedBusinessDays;
ViewBag.Result = BusinessDays; [/code] und platziert es an zwei Stellen innerhalb der Methode create httppost - Start des Controllers + Erstellen Abschnitt: [code]using System; using System.Collections; using System.Linq; using System.Threading.Tasks; using DocumentFormat.OpenXml.Office2010.Excel; using FluentValidation; using FluentValidation.AspNetCore; using FluentValidation.Results; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Research.Data; using ValidatorAttribute = ServiceStack.FluentValidation.Attributes.ValidatorAttribute;
using Research.Models; using Microsoft.CodeAnalysis.VisualBasic.Syntax;
namespace Research.Controllers { public class LofAccessHCsController : Controller { private readonly ResearchContext _context;
public LofAccessHCsController(ResearchContext context) { _context = context; }
// GET: LofAccessHCs/Create [HttpGet] public IActionResult Create( ) { ViewData["ProjectID"] = new SelectList(_context.PIF, "ProjectID", "ProjectID");
var type = _context.LofAccessType!.ToList(); ViewBag.type = type;
var yn = _context.YesNoList!.ToList(); ViewBag.yn = yn;
return View(); }
// POST: LofAccessHCs/Create [HttpPost] [ValidateAntiForgeryToken] public async Task Create( [Bind("LetterOfAccessHCID,ProjectID,DateRequestMade,RequestedBy,WithResearchPassport,DateIssued,DateofExpiry,IssuedTo,LoAType,businessDays")] LofAccessHC lofAccessHC, DateTime DateIssued, DateTime DateRequestMade, int BusinessDays, string action, string returnUrl) { LofAccessHCValidator lofaccesshcvalidator = new LofAccessHCValidator(); ValidationResult result = lofaccesshcvalidator.Validate(lofAccessHC);
// When validation failed, return to Index View if (!ModelState.IsValid) { foreach (var failure in result.Errors) { ModelState.AddModelError(failure.PropertyName, failure.ErrorMessage); }
ViewData["ProjectID"] = new SelectList(_context.PIF, "ProjectID", "ProjectID", lofAccessHC.ProjectID);
var type = _context.LofAccessType!.ToList(); ViewBag.type = type;
var yn = _context.YesNoList!.ToList(); ViewBag.yn = yn;
return View(lofAccessHC); } }
// Perform DB update after validation is passed if (action == "SaveAndBack" && !String.IsNullOrEmpty(returnUrl)) { try { _context.Add(lofAccessHC); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LofAccessHCExists(lofAccessHC.LetterOfAccessHCID)) { return NotFound(); } else { throw; } }
if (DateIssued.DayOfWeek == DayOfWeek.Saturday) calculatedBusinessDays--;
if (DateRequestMade.DayOfWeek == DayOfWeek.Sunday) calculatedBusinessDays--;
// Fix: Assign the calculated value to the outer scope variable 'BusinessDays' if needed. BusinessDays = (int)calculatedBusinessDays;
// Ensure all code paths return a value ViewBag.Result = BusinessDays;
// Ensure all code paths return a value // Redirection after model validation passed and successfully update to database var redirectUrl = Url.Action("Details", "PIFs", new { id = lofAccessHC.ProjectID });
if (string.IsNullOrEmpty(redirectUrl)) { return NotFound(); // Handle the case where the URL could not be generated }
Ich versuche, eine Liste vom Home-Controller an eine Indexansicht zu übergeben, aber wann immer ich mein Programm ausführe, erhalte ich diese Fehlermeldung
Ich habe ein kleines Problem gestoßen, als ich ein Projekt in ASP.NET Core MVC erstellt habe. Hier ist der Code für meinen customer.cs in Models Ordner:
Ich bin neu bei ASP.NET MVC. Ich habe ein einfaches Formular mit einer Schaltfläche zum Senden und einem HTML-Auswahlelement, das mit zwei Elementen gefüllt ist. Wenn das Formular an meinen...
Ich bin neu bei ASP.NET MVC. Ich habe ein einfaches Formular mit einer Schaltfläche zum Senden und einem HTML-Auswahlelement, das mit zwei Elementen gefüllt ist. Wenn das Formular an meinen...
Ich habe eine Webseite mit einer Karte, der Benutzer klickt auf eine Schaltfläche auf seinem mobilen Gerät und sollte ihnen dann seine Position basierend auf der Geolokalisierung ihres Geräts...