2

ビューを返そうとすると、MVC 4アプリケーションで作業しているときに、散発的なエラーが発生します。

この特定のケースでは、ビューを返そうとしていますreturn View("Home", model);。ここでメッセージを取得します。また、絶えずテストとデバッグを行っているときに散発的に発生するようで、ViewEngineはおかしくなりそうです。たとえば、これ以前は、単純なビューを実行していて、常にそこにあると見つからないと言いました。キャッシュのクリア、再起動など、およびまったく同じロジックの実行を組み合わせた後、それは機能しました。

そのため、ViewEngineでこの問題を修正する方法がわかりません。ビューに戻る直前に、モデルにレコードがあることを保証できます。PCからこのフォームにスクリーン印刷を添付できません---オプションがありません。

だから、悲惨な質問は:それがこのように散発的に起こらないこの問題をどのように解決するのですか?これは深刻な問題であり、修正されることを望んでいます。

ビューのプリコンパイルなどのためにScottHanselmansnugetパッケージを調べましたが、複雑すぎて余分な作業のようです。他に何かできることはないかと思っていました。

どんな助けでも大歓迎です....

これが私のGlobla.asaxファイルです:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = RouteParameter.Optional }
    );

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

誰かが答えてくれれば、私たちが取り組んでいるMVCアプリが停止するので、私はそれをいただければ幸いです!

.DataTokens.Add("area", "YOURAREANAME");の末尾にを追加してみましたMapRouteが、文字列の代わりに何を使用すればよいかわかりません。

さらに、なぜこれを行う必要があるのか​​(修正される場合)、誰かからの説明が必要なのかわかりません...

コントローラコードをチェックアウトしたい別の人のためのコードを追加しました。

[HttpPost]
        public ActionResult Refresh(ViewModelTemplate_Guarantors model)
        {
            try
            {
                model.Error = string.Empty;

                bool dbHasRows = db.ChkLoanFields(Convert.ToInt32(model.LoanId));

                if (!dbHasRows)
                {
                    ViewBag.ShowTemps = false;
                    model.Error = "Details not available for this LoanId.";
                    return View("Home", model);
                }
                else
                {
                    int TemplateCnt = 0;
                    int GuarantorCnt = 0;
                    ViewBag.ShowTemps = true;

                    ViewModelTemplate_Guarantors tg = db.SelectViewModelTemplate_Guarantors(Convert.ToInt32(model.LoanId), "1", model.SelectedDeptText, out TemplateCnt, out GuarantorCnt);

                    if (TemplateCnt > 0)
                        model.Templates = tg.Templates;
                    else 
                       model.ErrorT = "Templates not available for this LoanType.";

                    if (GuarantorCnt > 0)
                        model.Guarantors = tg.Guarantors;
                    else
                        model.ErrorG = "Guarantors not available for this LoanId.";

                    return View("Home", model);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

ディレクトリ構造が明確であるのに、ルーティングエンジンが次の場所に移動しようとする理由を理解しないでください:Views / Home / Index.cshtml

givienのエラーは以下のとおりで、「インデックス」ページも検索しません。

~/Views/Home/Home.aspx
~/Views/Home/Home.ascx
~/Views/Shared/Home.aspx
~/Views/Shared/Home.ascx
~/Views/Home/Home.cshtml
~/Views/Home/Home.vbhtml
~/Views/Shared/Home.cshtml
~/Views/Shared/Home.vbhtml
4

1 に答える 1

7

これを置き換えます:

return View("Home", model);

これとともに:

return View("Index", model);

完全なコード:

public ActionResult Refresh(ViewModelTemplate_Guarantors model)
{
    try
    {
        model.Error = string.Empty;

        bool dbHasRows = db.ChkLoanFields(Convert.ToInt32(model.LoanId));

        if (!dbHasRows)
        {
            ViewBag.ShowTemps = false;
            model.Error = "Details not available for this LoanId.";
            return View("Home", model);
        }
        else
        {
            int TemplateCnt = 0;
            int GuarantorCnt = 0;
            ViewBag.ShowTemps = true;

            ViewModelTemplate_Guarantors tg = db.SelectViewModelTemplate_Guarantors(Convert.ToInt32(model.LoanId), "1", model.SelectedDeptText, out TemplateCnt, out GuarantorCnt);

            if (TemplateCnt > 0)
                model.Templates = tg.Templates;
            else
                model.ErrorT = "Templates not available for this LoanType.";

            if (GuarantorCnt > 0)
                model.Guarantors = tg.Guarantors;
            else
                model.ErrorG = "Guarantors not available for this LoanId.";

            return View("Index", model);
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
}
于 2012-10-05T16:44:03.043 に答える