Почему я получаю эту ошибку "необработанное исключение произошло во время обработки запроса? "
Привет
Я делаю веб-приложение с помощью asp.net основная проблема заключается в том что я получаю эту ошибку каждый раз когда запускаю приложение я хочу знать что означает эта ошибка
Это Заголовок Ошибки:
An unhandled exception occurred while processing the request. FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, string format, ParamArray args)
Это Детали Ошибки:
FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list. System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, string format, ParamsArray args) string.FormatHelper(IFormatProvider provider, string format, ParamsArray args) string.Format(IFormatProvider provider, string format, object arg0, object arg1) System.ComponentModel.DataAnnotations.RegularExpressionAttribute.FormatErrorMessage(string name) Microsoft.AspNetCore.Mvc.DataAnnotations.ValidationAttributeAdapter<TAttribute>.GetErrorMessage(ModelMetadata modelMetadata, object[] arguments) Microsoft.AspNetCore.Mvc.DataAnnotations.Internal.RegularExpressionAttributeAdapter.GetErrorMessage(ModelValidationContextBase validationContext) Microsoft.AspNetCore.Mvc.DataAnnotations.Internal.RegularExpressionAttributeAdapter.AddValidation(ClientModelValidationContext context) Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultValidationHtmlAttributeProvider.AddValidationAttributes(ViewContext viewContext, ModelExplorer modelExplorer, IDictionary<string, string> attributes) Microsoft.AspNetCore.Mvc.ViewFeatures.ValidationHtmlAttributeProvider.AddAndTrackValidationAttributes(ViewContext viewContext, ModelExplorer modelExplorer, string expression, IDictionary<string, string> attributes) Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.AddValidationAttributes(ViewContext viewContext, TagBuilder tagBuilder, ModelExplorer modelExplorer, string expression) Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateInput(ViewContext viewContext, InputType inputType, ModelExplorer modelExplorer, string expression, object value, bool useViewData, bool isChecked, bool setId, bool isExplicitValue, string format, IDictionary<string, object> htmlAttributes) Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateTextBox(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, string format, object htmlAttributes) Microsoft.AspNetCore.Mvc.TagHelpers.InputTagHelper.GenerateTextBox(ModelExplorer modelExplorer, string inputTypeHint, string inputType, IDictionary<string, object> htmlAttributes) Microsoft.AspNetCore.Mvc.TagHelpers.InputTagHelper.Process(TagHelperContext context, TagHelperOutput output) Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output) Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext) AspNetCore.Views_Contacts_Create.<ExecuteAsync>b__20_0() in Create.cshtml + <input asp-for="PhoneNumber" type="tel" class="form-control"> Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(bool useCachedResult, HtmlEncoder encoder) Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output) Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext) AspNetCore.Views_Contacts_Create.ExecuteAsync() in Create.cshtml <big>+ ViewBag.Title = "Register";</big> Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts) Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, string contentType, Nullable<int> statusCode) Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result) Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync<TFilter, TFilterAsync>() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync() Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context) Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Это класс, который я определил валидацией
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Threading.Tasks; namespace Contact.Models { public class Contacts { public int ContactId { get; set; } [Required (ErrorMessage ="Please Provide A Value For First Name")] public string FirstName { get; set; } [Required (ErrorMessage ="Please Provide A Value For The Last Name")] public string LastName { get; set; } [Required(ErrorMessage ="Please Provide A Value For The WorkPlace ")] public string WorkPalce { get; set; } [Required(ErrorMessage ="Please Provide A Value For Phone Number")] [RegularExpression(@"^(01)[0-9]{9,}$", ErrorMessage = "The Phone Number Does Not Match The Pattern @(201)[0-9]{9}")] public int PhoneNumber { get; set; } [Required(ErrorMessage ="Please Provide Email Adress")] [RegularExpression(@"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z] {2,5})$", ErrorMessage ="Invalied Email Pattern")] public string Email { get; set; } [Required(ErrorMessage ="Please Provide A Data Of Birth")] [RegularExpression(@"^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$", ErrorMessage ="Please Enter A valid Date Of Birth Matches Pattern DD/MM/YYYY")] public string DateOfBirth { get; set; } public string Note { get; set; } } }
Это HTML код
@model Contacts @{ ViewBag.Title = "Register"; } <div class="container-fluid"> <form asp-action="Create" asp-controller="Contacts" method="post"> <div class="form-group"> <label asp-for="FirstName">First Name</label> <input type="text" class="form-control" asp-for="FirstName"> <span asp-validation-for="FirstName"></span> </div> <div class="form-group"> <label asp-for="LastName">Last Name</label> <input type="text" class="form-control" asp-for="LastName"> <span asp-validation-for="LastName"></span> </div> <div class="form-group"> <label asp-for="WorkPalce">Work</label> <input type="text" class="form-control" asp-for="WorkPalce"> <span asp-validation-for="WorkPalce"></span> </div> <div class="form-group"> <label asp-for="PhoneNumber">Phone Number</label> <input asp-for="PhoneNumber" type="tel" class="form-control"> <span asp-validation-for="PhoneNumber"></span> </div> <div class="form-group"> <label asp-for="Email">Email</label> <input type="email" class="form-control" asp-for="Email"> <span asp-validation-for="Email"></span> </div> <div class="form-group"> <label asp-for="DateOfBirth">Date Of Birth</label> <input type="date" class="form-control" asp-for="DateOfBirth"> <span asp-validation-for="DateOfBirth"></span> </div> <div class="form-group"> <label asp-for="Note">Comments</label> <textarea class="form-control" asp-for="Note"></textarea> </div> <button type="submit" class="btn btn-primary">Submit</button> </form> </div>
Нужно знать в чем проблема
Что я уже пробовал:
попытался удалить ввод для номера телефона который делает проблему приложение работает и попытался изменить регулярное выражение для этого ввода не работает