Asp.net mvc 3 操作方法参数始终为空

Asp.net mvc 3 操作方法参数始终为空,asp.net-mvc-3,Asp.net Mvc 3,我不明白为什么当它碰到我的动作方法时,carFileName是空的。我调试了视图,当我迭代该foreach循环时,在该循环的每次迭代中,carContent.CarFileName的值确实不同。因此,对于提交的每个按钮,它应该提交与该特定按钮关联的carFileName @if (Model.CarFiles != null && Model.CarnFiles.Count > 0) { @foreach (CarContent carContent in Mode

我不明白为什么当它碰到我的动作方法时,carFileName是空的。我调试了视图,当我迭代该foreach循环时,在该循环的每次迭代中,carContent.CarFileName的值确实不同。因此,对于提交的每个按钮,它应该提交与该特定按钮关联的carFileName

@if (Model.CarFiles != null && Model.CarnFiles.Count > 0)
{
    @foreach (CarContent carContent in Model.CarFiles)
    {
        using (Html.BeginForm("GetfileDownloadUrl", "Car", FormMethod.Get, new { carId = Model.CarId, userId = Model.UserId, @carFileName = carContent.CarFileName }))
        {
            @Html.Hidden("userId", Model.UserId);
            @Html.Hidden("carId", Model.CarId);
            @Html.Hidden("carFileName", carContent.CarFileName);        
            <p><input type="submit" name="SubmitCommand" value="download" /> @carContent.Name</p>
        }
    }
}
以下是路线:

routes.MapRoute("CarDownloadFile", "Cars/{carId}/{userId}/{carFileName}", new { controller = "Car", action = "GetFileDownloadUrl", carnId = UrlParameter.Optional, userId = UrlParameter.Optional, carFileName = UrlParameter.Optional });   

可能是因为在您的路线中,您引用了carFileName,但您的操作方法采用了carFileUrl,并且您在RouteValueDictionary中的carId拼写为carId

我在您的MapRoute中看到了carId,它不应该是carId吗?我还看到了carFileName MapRoute vs carFileUrl Controller。从操作方法param到路由参数再到表单中定义的匿名方法中的属性的名称是否必须完全相同?那么排序呢?我可能错了,但我很确定它们必须是相同的名称,除非您需要更改参数,否则最好保持这种方式,您可以轻松找到它的用法。订购一定要一样。
routes.MapRoute("CarDownloadFile", "Cars/{carId}/{userId}/{carFileName}", new { controller = "Car", action = "GetFileDownloadUrl", carnId = UrlParameter.Optional, userId = UrlParameter.Optional, carFileName = UrlParameter.Optional });