1

多くの人が MVC4 にいくつかの優れた新機能があることを知っているように、私は ContextDependentView にオーバーロードを追加しようとして苦労しています。ContextDependentView のオーバーロード メソッドが 1 つの引数をとらないというエラーが表示されます。機能していた私の元のコードはこれでした

// This worked fine
return View(new ModelSample { getInfo= info, Retrieving= Retrieve })

// This is now what I have tried to do that doesn't work
return ContextDependentView(new ModelSample { getInfo= info, Retrieving= Retrieve })

//This is the method for ContextDependentView()


private ActionResult ContextDependentView()
    {
        string actionName = ControllerContext.RouteData.GetRequiredString("action");
        if (Request.QueryString["content"] != null)
        {

            ViewBag.FormAction = "Json" + actionName;
            return PartialView();
        }
        else
        {
            ViewBag.FormAction = actionName;
            return View();
        }
    }

オーバーロードがないことは明らかですが、return View()のようなモデルを受け入れるためにContextDependentViewメソッドにオーバーロードを追加するにはどうすればよいですか?

4

1 に答える 1

0

このオーバーロードをコントローラーに追加します。

private ActionResult ContextDependentView(SampleModel model)
{
    string actionName = ControllerContext.RouteData.GetRequiredString("action");
    if (Request.QueryString["content"] != null)
    {

        ViewBag.FormAction = "Json" + actionName;
        return PartialView();
    }
    else
    {
        ViewBag.FormAction = actionName;
        return View();
    }
}

それはうまくいくはずです...

于 2013-08-11T07:49:49.080 に答える