tags:

views:

54

answers:

3

This throws error:

public static void RenderPartialForEach<T>
(this HtmlHelper helper, string partialName, IList<T> list)
{
    foreach (var item in list)
       helper.RenderPartial(partialName, item);
}

=>

Error Message: CS1519: Invalid token '(' in class, struct, or interface member declaration

Line 283: #line default
Line 284: #line hidden
Line 285: @__w.Write("\r\n \r\n\r\n\r\n");
Line 286: }
Line 287:

Is it possible to create clean htmlhelper
which is able to render partial views for every item in list passing it as model?

Edit:
That was just a blunder from my side. I forgot to add '<% } %>'.
And got confused cause of error message. ^^

+1  A: 

Where are you declaring such a thing? Try writing that extension method in a separate static class in a code file, not inline in .aspx.

Mehrdad Afshari
Did that (15 characters -_-)
Arnis L.
The error message looks like a problem in `.aspx`, not in code. How are you calling it?
Mehrdad Afshari
A: 

Just a guess... you are implementing a generic method (of T) but you are not actually replacing the generic parameter (T) with a type argument?

martijn_himself
Nope... it's not so bad with me. Actually - it seems that error is somewhere else and cause of vagueness of error message i got confused completely.
Arnis L.
+1  A: 

You need to declare the method in a class. It's not obvious that you are doing that, but it would certainly cause the type of error that you are seeing.

  public static class CustomHtmlHelperExtensions
  {
       public static void RenderPartialForEach<T>(
              this HtmlHelper helper,
              ...
  }

EDIT: In retrospect, given the text of the error, I suspect that the error lies elsewhere in your markup. Perhaps, you're missing a parenthesis around an if statement or foreach clause.

tvanfosson
Actually, i deleted my question already - but then reopened just to mark your answer as accepted. Quite amazing one (cause of info provided).
Arnis L.