簡體   English   中英

即使存在當前視圖和其他視圖,也無法找到該視圖

[英]View can not be found even though its present and other views are

我有一段代碼引用了一個特定的視圖。 該代碼是

private ActionResult PrepareSuccessResponse(PaymentProcessingContext paymentContext)
{
    this.RemoveLinkedMemberCookie();
    if (paymentContext.Provider.PaymentProviderType == "Worldpay")
    {
        return View("~/Areas/Payments/Views/Confirmation/WorldPayPaymentResponsePage.cshtml", paymentContext.ConfirmationUrl);
    }
    return Redirect(paymentContext.ConfirmationUrl);
}

但是,這將返回標准錯誤:

找不到視圖“〜/ Areas / Payments / Views / Confirmation / WorldPayPaymentResponsePage.cshtml”或其主視圖,或者沒有視圖引擎支持搜索到的位置。 搜索了以下位置:〜/ Areas / Payments / Views / Confirmation / WorldPayPaymentResponsePage.cshtml

等等,但是在同一控制器中,使用這兩個函數返回相似位置的另一個視圖

private const string FailedResponseViewPath = "~/Areas/Payments/Views/ResponseFailures/";
private static string GetViewPath(string viewName)
{
    return string.Format("{0}{1}.cshtml", FailedResponseViewPath, viewName);
}
private ActionResult PrepareFailedProcessingResponse(PaymentProcessingContext paymentContext)
{
    return View(GetViewPath("ProcessingError"), paymentContext);
}

文件結構如下圖所示,文件控制器為PaymentMvcController.cs

文件結構圖像

這與此處提出的問題非常相似- 找不到視圖或其主視圖,或者沒有視圖引擎支持搜索到的位置 第二個參數“ paymentContext.ConfirmationUrl”被理解為母版頁的路徑。 為了明確地使它成為模型,您應該將返回值更改為此:

return View("~/Areas/Payments/Views/Confirmation/WorldPayPaymentResponsePage.cshtml", model:paymentContext.ConfirmationUrl);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM