简体   繁体   English

href链接未传递参数值

[英]href link not passing parameter value

I have a section of code in my view that displays an image and a URL on click of it. 我的视图中有一段代码,单击该代码即可显示图像和URL。 The URL is to a page on the site and directs it to that action method. 该URL指向网站上的页面,并将其定向到该操作方法。 I have the parameter as part of the URL, but in the Action method the parameter shows null.Hence I am redirected to the appropriate page but none of my functionalities inside the action method works. 我将参数作为URL的一部分,但是在Action方法中该参数显示为null。因此,我被重定向到相应的页面,但是action方法内部的所有功能均无效。

Here is my code. 这是我的代码。

View: 视图:

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

The value of @item.Image URL which I am getting from the database is http://localhost/TestProject/Home/DemoPage/b9f074fc-f86c-4866-a7b3-33e43025293f 我从数据库中获取的@ item.Image URL的值为http:// localhost / TestProject / Home / DemoPage / b9f074fc-f86c-4866-a7b3-33e43025293f

And my action method in Home controller is 我在Home控制器中的操作方法是

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

This is my mapping route in Route.config 这是我在Route.config中的映射路线

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

What am I missing? 我想念什么?

I think that you need to either change 'blockId' to just 'id' or add the following route: 我认为您需要将'blockId'更改为'id'或添加以下路线:

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

I would think it makes more sense to just rename your parameter in the signature rather than creating a nearly identical route for this action method. 我认为仅在签名中重命名参数而不是为此操作方法创建几乎相同的路由会更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM