如何从mvc中的cshtml视图将参数传递给控制器

问题描述 投票:0回答:1

net MVC 4我遵循了有关如何从mvc中的cshtml视图将参数传递给控制器​​的Microsoft教程,并且不断收到错误消息,指出找不到资源。如果在cshtml中放置断点,我可以实际上看到了Id的值,但它根本没有命中控制器,似乎找不到它

    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: /UploadLogs/DisplayUploadedFileContents/89

这是我的控制器方法

{
    public class DisplayUploadedFileController : Controller
    {
        private MarketingDBEntitiesModel db = new MarketingDBEntitiesModel();
        // GET: DisplayUploadedFile
        public ActionResult DisplayUploadedFileContents(int UploadId)
        {
            return View(db.marketingdbclients_dataTable.OrderByDescending(r => r.ClientId).Where(r => r.ClientDataId < 1000).ToList());
           // return View();.
        }
    }
}

我在cshtml中的行

<td>

                @*@Html.ActionLink("Details", "Details", new { id = item.UploadId })*@
                @Html.ActionLink("Details", "DisplayUploadedFileContents", new { id = item.UploadId })

            </td>

我的路线配置

 routes.MapRoute(
      name: "DisplayUploadedFileContents",
      //url: "",
      url: "{controller}/{action}/{id}",
      defaults: new { controller = "DisplayUploadedFile", action = "DisplayUploadedFileContents", id = UrlParameter.Optional });
c# asp.net asp.net-mvc entity-framework-6 asp.net-mvc-routing
1个回答
0
投票
url: "{controller}/{action}/{id}

您不尊重路由配置。尝试:

© www.soinside.com 2019 - 2024. All rights reserved.