1

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?

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • 1
    For more information on the differences between `Partial` and `RenderPartial` see this answer. http://stackoverflow.com/questions/5248183/html-partial-vs-html-renderpartial-html-action-vs-html-renderaction/5248218#5248218 – Mark Coleman Jul 01 '11 at 15:42

2 Answers2

4

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.

Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101
0

You need to create a model with the field word

public class SynonymFinderModel
{
    public string Word {get; set;}
}

Then, in your view, you have

@Html.Partial("SynonymFinder", new SynonymFinderModel { Word = "something"})
mccow002
  • 6,754
  • 3
  • 26
  • 36