Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC 2 RouteLink method
    text
    copied!<p>I'm new to ASP.NET MVC and can't figure this out. Working through the Nerdinner example from Professional ASP.NET MVC 2, I copied the PaginatedList helper class and decided to improve it so the forward and back links could be generated by a method within the class instead of writing them out in every view page. I copied this from the view that it was in, Index.aspx:</p> <pre><code>if (Model.HasPreviousPage) { Response.Write(Html.RouteLink("&lt;&lt;&lt;", "Users", new { page=(Model.PageIndex-1) })); } </code></pre> <p>And used it to create this method within Helpers\PaginatedList.cs:</p> <pre><code>public string NavLinks() { if (HasPreviousPage) { return Html.RouteLink("&lt;&lt;&lt;", "Users", new { page=(PageIndex-1) }); } } </code></pre> <p>(HasPreviousPage is a simple method within PaginatedList.)</p> <p>Straight away it complains that "The name 'Html' does not exist in the current context, so I modified it to take a parameter:</p> <pre><code>public string NavLinks(HtmlHelper Html) </code></pre> <p>Now I get "'System.Web.Mvc.HtmlHelper' does not contain a definition for 'RouteLink' and no extension method 'RouteLink' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)".</p> <p>According to Microsoft documentation on LinkExtensions.RouteLink method, "In Visual Basic and C#, you can call this method as an instance method on any object of type HtmlHelper". Do they lie?</p> <p>Help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload