我無法弄清楚爲什麼當它碰到我的操作方法時,carFileName爲null。我調試了視圖,當我遍歷該foreach循環時,carContent.CarFileName的循環的每次迭代中確實存在不同的值。因此,對於每個按鈕提交時,它應提交與該特定按鈕關聯的carFileName。Action Method Param始終爲空
@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>
}
}
}
這裏是我的操作方法的簽名:
[HttpGet]
public string GetFilDownloadUrl(string carFileUrl, int carId, int userId)
{
...
}
,路線如下:
routes.MapRoute("CarDownloadFile", "Cars/{carId}/{userId}/{carFileName}", new { controller = "Car", action = "GetFileDownloadUrl", carnId = UrlParameter.Optional, userId = UrlParameter.Optional, carFileName = UrlParameter.Optional });
我在'MapRoute'中看到'carnId',不應該是'carId'嗎?我還看到'carFileName'(MapRoute)vs'carFileUrl'(Controller)。 – Silvermind 2012-03-30 21:41:29