Search code examples
asp.net-mvcasp.net-mvc-3partial-viewsrenderpartial

RenderPartial not working


I have a simple partial view which returns (renders) a list of synonyms of a given word. Then I'd like to use this partial view inside another view and I use @Html.RenderPartial("SynonymFinder", new { word = "Something" }) inside my view. But I get this error:

CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

This is the simplest scenario. I even removed the parameters and used @Html.RenderPartial("SynonymFinder"), but still the same problem. What's wrong?


Solution

  • In MVC 3 you should use:

    @Html.Partial("SynonymFinder", new ViewDataDictionary { { word = "Something" } })
    

    Note that the 2nd parameter is of type ViewDataDictionary. If you don't pass it explicitly like that, the helper will use the overload that takes an object as the 2nd parameter and uses it as a Model instead of as route values.