0

我的部分视图没有加载,我正在使用 AjaxActionLink 这是我的视图,我称之为部分视图

@foreach (var p in Model.Rooms)
{


<div class="room">
    <h3>@p.RoomTitle</h3>
    <img src="@p.PhotoRoom" alt="room"/>
    <h4>@p.TitlePrice</h4>
    <blockquote>@p.Description</blockquote>

    @Ajax.ActionLink("Order room", "PartialDetail", new { @p.RoomID }, new AjaxOptions { UpdateTargetId = "results", LoadingElementId = "loading",HttpMethod = "POST",InsertionMode = InsertionMode.InsertAfter})

</div>

}

这是我的控制器

  public PartialViewResult PartialDetail(int roomid)
    {

        Room rooms =
            repository.Room.FirstOrDefault(p => p.RoomID == roomid);
        var viewModel = new RoomEditViewModel
                            {
                                RoomID = rooms.RoomID,
                                RoomTitle = rooms.RoomTitle,
                                Description = rooms.Description,
                                PhotoRoom = rooms.PhotoRoom
                            };
        ViewBag.room = roomid;

            return PartialView(viewModel);


    }
4

1 回答 1

1

修复了您的 ajax 操作链接

你设置的

 @Ajax.ActionLink("Order room", "PartialDetail", new { @p.RoomID }

应该

 @Ajax.ActionLink("Order room", "PartialDetail", new { roomid = @p.RoomID }

作为建议,在您的操作中设置接受的协议

[HttpPost]
public PartialViewResult PartialDetail(int roomid)
于 2013-04-21T17:20:51.443 回答