asp.net MVC3 custom route for Doddle Report
I am using doodle report which outputs quick reports in pds, html and xls formats. It is working fine as shown in the documentation link below:
http://doddlereport.codeplex.com/wikipage?title=Web%20Reporting
Now i need to be able to pass an ID value to the controller so report is generated dynamically.
the default route is as follows:
return routes.MapRoute("DoddleReport",
"{controller}/{action}.{extension}",
new { controller = defaultAction, action = defaultAction },
new { extension = new ReportRouteConstraint() }
which outputs the following url localhost/Report/ReadMeters.htm
when using the following
actionlink @Html.ActionLink("HTM", "ReadMeters", new{ extension = "htm"})
I have tried to add a new route in global.asax that will accept an ID parameter as follows:
routes.MapRoute("DoddleReportExtension",
"{controller}/{action}.{extension}/id",
new { controller = "Report", action = "Index" },
new { extension = new ReportRouteConstraint(),
id = UrlParameter.Optional
}
);
and passing开发者_Python百科 the value using actionlink:
@Html.ActionLink("View", "ReadMeters", new { id = ViewBag.ID, extension = "htm" }
but this is outputting url localhost/Report/ReadMeters.htm?id=19
this does not work and i get the following error:
Server Error in '/' Application.
The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.Requested URL: /Report/ReadMeters.htm
Any Ideas how to fix this please? This is my first MVC project and so far have relied on the default routing mechanisms for other areas of the project but got stuck on this one.
Your help is appreciated, thanks
I know I'm late here, but I'm the author of DoddleReport and just wanted to say that this issue has been resolved in the latest source and NuGet package. It also supports MVC Areas.
Hope the project has been helping you!
you could do something like this ...
routes.MapRoute("DoddleReportExtension",
"{Controller}/{Action}/{Extension}/{id}/",
new { controller = Report, action = Index,Extension=new ReportRouteConstraint(), id=UrlParameter.Optional });
and then you can send the extension and the id to ActionResult..
public ActionResult showItem(string Extension)
{
//view stuff here.
}
public ActionResult showItem(string Extension, int id)
{
//view stuff here
}
精彩评论