通过html.actionlink asp.net-mvc传递多个参数

时间:2017-04-19 09:51:55

标签: asp.net-mvc html.actionlink

我是net-mvc.i的新手有一个页面,在我从数据库中提取并在页面上使用foreach循环列出的房间列表中有一个checkInDate。我在每个列表上都有一个按钮,选中后应该传递房间的id并checkinDate。我试图通过按钮中的锚标记传递checkInDate输入以及所选房间的ID。我该怎么做呢。 here is the view of the page

@model thePortfolio.Models.CustomerNRoomViewModel

@{
    ViewBag.Title = "Index Booking";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="box">

    <h4>Room</h4>
    @using (Html.BeginForm())
    {
        <div class="box">
            @Html.LabelFor(model => model.Book.CheckInDate, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
            @Html.EditorFor(model => model.Book.CheckInDate, new { htmlAttributes = new { @class = "form-control" } })
            </div>
        </div>
        <br />

        foreach (var item in Model.RoomList)
        {
            var image = @item.RoomType.ToString() + ".jpg";
            image = image.Replace(" ", String.Empty);

            <div class="row box">
                <div class="col-sm-4">
                    <img class="img-responsive" src="~/img/rooms/@image">
                </div>

                <div class="col-sm-6 text-left">

                    @Html.DisplayFor(m => item.RoomId)<br />
                    @Html.DisplayFor(m => item.RoomType)<br />
                    @Html.DisplayFor(m => item.Description)

                </div>

                <div class="col-sm-2">
                    <h4>Rates from</h4>
                    <i>per night</i>
                    <h2 style="color:red">$@item.Price</h2>

                    @if (item.BookingStatus)
                    {
                        <button type="button" disabled>Not Available</button>
                    }
                    else
                    {
                        <button>@Html.ActionLink("Book This", "bookRoom", new { id = item.RoomId })</button>


                    }
                </div>
            </div>
                <p></p>


        }

    }
</div>

1 个答案:

答案 0 :(得分:0)

唉... 我认为在你的控制器中,你需要添加一个带有id参数的方法。像这样:

[HttpPost]
public ActionResult Edit(int id, CustomerNRoomViewModel model)

id参数应作为http调用的查询字符串中的值发送。