簡體   English   中英

href鏈接未傳遞參數值

[英]href link not passing parameter value

我的視圖中有一段代碼,單擊該代碼即可顯示圖像和URL。 該URL指向網站上的頁面,並將其定向到該操作方法。 我將參數作為URL的一部分,但是在Action方法中該參數顯示為null。因此,我被重定向到相應的頁面,但是action方法內部的所有功能均無效。

這是我的代碼。

視圖:

<a class="lnkImage" href="@item.ImageURL" target="_blank"><img id="PrivateimgPreview" src="@item.ActualImage"/></a>

我從數據庫中獲取的@ item.Image URL的值為http:// localhost / TestProject / Home / DemoPage / b9f074fc-f86c-4866-a7b3-33e43025293f

我在Home控制器中的操作方法是

public ActionResult DemoPage(string blockId)
{
    //Some code here
    return(View);
}

這是我在Route.config中的映射路線

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );  

我想念什么?

我認為您需要將'blockId'更改為'id'或添加以下路線:

routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{blockId}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );  

我認為僅在簽名中重命名參數而不是為此操作方法創建幾乎相同的路由會更有意義。

暫無
暫無

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

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