【问题标题】:Render a partial view inside a Jquery modal popup ( 2 different models)在 Jquery 模式弹出窗口中渲染部分视图(2 个不同的模型)
【发布时间】:2015-05-01 16:26:05
【问题描述】:

我的项目是房间预订。我有 View 在房间模型上显示房间的 id 和她在 foreach 上的特征:

@model IEnumerable<Room>

<div class="roomConteiner">
        @foreach (Room room in Model)
        {
                <table class="simple-little-table" cellspacing='0'>
                    <tr>
                        <td> @room.NumberRoom </td>
                        <td>@room.Categoryid</td>
                        <td> @room.NumberOfSeats </td>
                        <td> @room.CostPerNight </td>
                        <td>

                            <button class="roomBookingButton" data-roomid="@room.Id">Booking</button>
                        </td>
                    </tr>
                </table>
            </div>
        }
    </div>

我有 JS,它在 buttonClick 上呈现一个 Jquery 模式弹出窗口内的部分视图:

</script>

<div id="dialog-modal" > @Html.Partial("UserPartial", new Client()) </div>

<script type="text/javascript">
$(function () {
    $("#dialog-modal").dialog({
        autoOpen: false,
        width: 400,
        height: 400,
        resizable: false
    });

    $('.roomConteiner').on("click", ".roomBookingButton", function () {

        $("#dialog-modal").dialog("open");
    });
});
</script>

用户部分:

  @model Client
    <div class="editor-label">
                @Html.Label("Surname")
                @Html.TextBoxFor(model => model.Surname)
            </div>
            <div class="editor-label">
                @Html.Label("Name")
                @Html.TextBoxFor(model => model.Name)
                @Html.ValidationMessageFor(model => model.Name)
            </div>
<input type="submit" id="submit" value="Booking" />

如何在foreach的弹出窗口中传输NumberRoom?例如,在弹出窗口中给我的信息:“您选择了 5 号房间”请填写您的数据:姓名、姓氏......

控制器:

[HttpGet]
        public PartialViewResult UserPartial()
        { 
            return PartialView("UserPartial" , new Client());
        } 

【问题讨论】:

    标签: javascript jquery asp.net-mvc


    【解决方案1】:

    这与用户“Alex Da”发布的问题完全相同。

    Render a partial view inside a Jquery modal popup

    要回答有关获取 ID 的问题,您可以获取该值:

    $(".roomBookingButton").on("click", function () {
      var id = $(this).data("roomid");
    
      // make call to your partial action
      $.get('@Url.Action("UserPartial", "Home")', { id: id }, function (view) {
        $("dialog-modal").html(view);
      });
    });
    

    然后调整你的局部视图动作:

    [HttpGet]
    public PartialViewResult UserPartial(int id)
    {
      var client = db.Clients.Single(id);
    
      return PartialView("UserPartial" , client);
    } 
    

    就是这样。

    【讨论】:

    • 'System.Data.Entity.DbSet' 不包含 'Single' 的定义和最佳扩展方法重载 'System.Linq.Queryable.Single (System.Linq.IQueryable, System.Linq.Expressions.Expression>)' 有一些无效参数
    • public PartialViewResult SaveUserDBPartial(string numberRoom) { var client = db.Client.Single(numberRoom); return PartialView("SaveUserDBPartial" , 客户端); } 错误(((((
    • 您应该编辑原始问题以包含“房间”和“客户”之间的关系。据我所知,目前在选择房间和显示客户信息之间没有联系……您给我们的唯一信息是房间有一个 ID。这个房间 ID 如何影响客户数据的显示?
    • 您需要哪些项目信息来帮助我?房间和客户之间的沟通跨表订房和订房.......Client-Booking-RoomBoking-Room
    • 当有人单击“预订”按钮时,您希望弹出一个包含属性“姓氏”和“姓名”的模型 [Client] 的模式。我的问题是这个 [Client] 模型与 [Room] 模型有什么关系?他们共享外键吗?两个模型之间需要存在关系才能在您的模式弹出窗口中显示正确的 [Client] 数据。
    猜你喜欢
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-07
    • 2012-05-30
    • 1970-01-01
    • 2012-02-22
    相关资源
    最近更新 更多