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();
        }
    }

我显然看到没有重载,但是如何向 ContextDependentView 方法添加重载以接受我的模型,例如return View() ..thanks

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 回答