gpt4 book ai didi

asp.net - 当 ModelState 有错误时,"Value cannot be null or empty. Parameter name: contentPath"在回发时最意外的行上

转载 作者:行者123 更新时间:2023-12-03 16:28:56 24 4
gpt4 key购买 nike

我已经连续两个小时与这个怪物讨价还价了。

我收到此错误:

Value cannot be null or empty. Parameter name: contentPath



在我看来这一行:
@Html.ValidationMessageFor(model => model.IssueName, 
"", new { @class = "text-danger" })

下面给出的堆栈跟踪似乎表明调用 Url.Content已经打过,但我没有打过这样的电话。下面是堆栈跟踪,然后是导致错误的行周围的更多代码行:

[ArgumentException: Value cannot be null or empty. Parameter name: contentPath] System.Web.Mvc.UrlHelper.GenerateContentUrl(String contentPath, HttpContextBase httpContext) +125
System.Web.Mvc.UrlHelper.Content(String contentPath) +26
ASP._Page_Views_Journal_EditIssue_cshtml.Execute() in MyProject\Views\Journal\EditIssue.cshtml:45
System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +197
System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +105
System.Web.WebPages.StartPage.RunPage() +17
System.Web.WebPages.StartPage.ExecutePageHierarchy() +64
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +78
System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +256
System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +291 System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1
filters, Int32 filterIndex, ResultExecutingContext preContext,
ControllerContext controllerContext, ActionResult actionResult) +56

System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList
1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList1 filters, ActionResult actionResult) +52

System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
+173 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult
asyncResult) +100

System.Web.Mvc.Async.WrappedAsyncResult
1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49

System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult
asyncResult) +27

System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult
asyncResult, ExecuteCoreState innerState) +13

System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49

System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult
asyncResult, Controller controller) +12

System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49

System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26

System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult
asyncResult) +10

System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult
asyncResult, ProcessRequestState innerState) +21

System.Web.Mvc.Async.WrappedAsyncVoid
1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9644097 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155



引发异常的行周围的代码行是:
<div class="form-group">
@Html.LabelFor(model => model.IssueName, htmlAttributes: new { @class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.IssueName, new { htmlAttributes = new { @class = "form-control", id = "IssueName" } })
@Html.ValidationMessageFor(model => model.IssueName, "", new { @class = "text-danger" })
</div>
</div>

重要信息

奇怪的是,只有当我从 post-back 返回时才会引发异常,而不会在我第一次加载 View 时引发异常,甚至在 ModelState 时也不会引发异常。没有错误。它仅在 ModelState 时引发回发后有错误。

这是一些服务器端代码,但我没有看到它可能做错的任何原因:
[HttpPost]
public async Task<ActionResult> EditIssue(EditIssueViewModel viewModel)
{
viewModel.AvailableTags = BusinessManager.GetAllTags();

if (viewModel.IssuePDFFile == null || viewModel.IssuePDFFile.ContentLength == 0)
{
ModelState.AddModelError("", "Please select a file to upload.");
return View(viewModel);
}

var fileInfo = new FileInfo(viewModel.IssuePDFFile.FileName);
if (!StaticData.AcceptedContentTypes.Contains(viewModel.IssuePDFFile.ContentType, StringComparer.InvariantCultureIgnoreCase) ||
!fileInfo.Extension.Equals(".pdf", StringComparison.InvariantCultureIgnoreCase))
{
ModelState.AddModelError("", "You can only select a PDF file.");
return View(viewModel);
}

if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors)
.Select(e => new { e.ErrorMessage, e.Exception });

var errorList = errors.ToList();

errorList.ForEach(e => Debug.Print(e.ErrorMessage));
errorList.ForEach(e => ModelState.AddModelError("", e.ErrorMessage));

return View(viewModel);
}

var operationResult = await BusinessManager.EditIssueAsync(viewModel);

if (!operationResult.Succeeded)
{
ModelState.AddModelError("", operationResult.FailureMessage);
return View(viewModel);
}

viewModel = (EditIssueViewModel)BusinessManager.GetIssueWithRelationships(viewModel.IssueId);
viewModel.SuccessMessage = operationResult.SuccessMessage;
return View(viewModel);
}

最佳答案

碉堡了!

如果您曾经,曾经,曾经遇到过此错误,请记住,导致此错误的原因只有一个,并且只有一个。

Somewhere in the network of lines on your view, you have passed a null value to the @Url.Content method. Period.



它报告异常的行可能与异常无关,并且可能距离罪魁祸首一两英里。

搜索,搜索,疯狂地搜索。 :-)

这就是我如何找到解决方案并从我的痛苦中解脱出来的方法。

关于asp.net - 当 ModelState 有错误时,"Value cannot be null or empty. Parameter name: contentPath"在回发时最意外的行上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38231453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com