簡體   English   中英

asp.net MVC3自定義路由的Doddle報告

[英]asp.net MVC3 custom route for Doddle Report

我正在使用Doodle報告,該報告以pds,html和xls格式輸出快速報告。 如下面的文檔鏈接所示,它工作正常:

http://doddlereport.codeplex.com/wikipage?title=Web%20Reporting

現在,我需要能夠將ID值傳遞給控制器​​,以便動態生成報告。

默認路由如下:

     return routes.MapRoute("DoddleReport",
                "{controller}/{action}.{extension}",
                new { controller = defaultAction, action = defaultAction },
                new { extension = new ReportRouteConstraint() }

使用以下localhost/Report/ReadMeters.htm時會輸出以下URL localhost/Report/ReadMeters.htm

actionlink @Html.ActionLink("HTM", "ReadMeters", new{ extension = "htm"})

我試圖在global.asax中添加一條新路由,該路由將接受ID參數,如下所示:

 routes.MapRoute("DoddleReportExtension",
                "{controller}/{action}.{extension}/id",
                new { controller = "Report", action = "Index" },
                new { extension = new ReportRouteConstraint(),
                id = UrlParameter.Optional
                }
                );

並使用actionlink傳遞值:

@Html.ActionLink("View", "ReadMeters", new { id = ViewBag.ID, extension = "htm" }

但這輸出URL localhost/Report/ReadMeters.htm?id=19

這不起作用,並且出現以下錯誤:

'/'應用程序中的服務器錯誤。
無法找到該資源。
說明:HTTP 404.您要查找的資源(或其中一個依賴項)可能已被刪除,名稱已更改或暫時不可用。 請查看以下網址,確保拼寫正確。

要求的網址:/Report/ReadMeters.htm

有任何想法如何解決這個問題嗎? 這是我的第一個MVC項目,到目前為止,該項目的其他區域都依賴於默認的路由機制,但仍受此限制。

感謝您的幫助,謝謝

我知道我來晚了,但是我是DoddleReport的作者,只是想說這個問題已經在最新的源代碼和NuGet包中得到了解決。 它還支持MVC區域。

希望該項目對您有所幫助!

你可以做這樣的事情...

routes.MapRoute("DoddleReportExtension",
   "{Controller}/{Action}/{Extension}/{id}/",
    new { controller = Report, action = Index,Extension=new ReportRouteConstraint(), id=UrlParameter.Optional });

然后您可以將擴展名和ID發送給ActionResult。

public ActionResult showItem(string Extension)
{
    //view stuff here.
}

public ActionResult showItem(string Extension, int id)
{
    //view stuff here
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM