How can I just write
Response.Write("<a href='/someurl'>Some Text</a>");
Instead of
Response.Write(Html.ActionLink(...));
This reason I am after this is because I am writing a Pagination ViewUserControl. In the control I want it to show page numbers, next and previous pages etc.
When I use the following code
Response.Write(Html.ActionLink(page.ToString(), HttpContext.Current.Request.RawUrl, new { page = page }));
The link is written out as http://localhost:61293/customers/customers/System.Web.Mvc.UrlParameter/page2 which is obviously incorrect.
HttpContext.Current.Request.RawUrl == "/customers/" in this example. I would have expected that the resultant Url was then /customers/page2 as opposed to what is actually written out.
My routes are set up like so:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/page{page}", // URL with parameters
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional,
page = UrlParameter.Optional
} // Parameter defaults
);
Can anyone shed some light?
Based on your update, you shouldn’t be using
HttpContext.Current.Request.RawUrlas the action of yourActionLink.http://msdn.microsoft.com/en-us/library/dd505040(v=VS.90).aspx
As you can see,
HttpContext.Current.Request.RawUrlwill not match any of your actions. Try writing: