【问题标题】:Recover only part of the view仅恢复部分视图
【发布时间】:2013-11-01 17:11:45
【问题描述】:

我正在尝试开发一个模型表单并将我的视图插入其中,就像这样。

但是Entity FrameWork是带菜单和页脚的所有视图,像这样。

如何移除菜单和视图的页脚并且只有字段和标签?

视图

    @model TPTMVC.Models.User
@using TPTMVC.Models;

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>
@using (@Html.BeginForm())
{ 

    <fieldset>
        <legend>User</legend>

        <div class="display-label">FirstName</div>
        <div class="display-field">@Model.FirstName</div>

        <div class="display-label">LastName</div>
        <div class="display-field">@Model.LastName</div>

        <div class="display-label">Number</div>
        <div class="display-field">@((Model.billingDetail).Number)</div>

        <div class="display-label">Owner</div>
        <div class="display-field">@((Model.billingDetail).Owner)</div>


    </fieldset>
}

拉伸控制器

public ViewResult Details(int id)
        {
            User user = context.User.Single(x => x.UserId == id);
            return View(user);
        }

将视图插入模型表单

链接

@Html.ActionLink("Details", "Details", new { id = item.UserId }, new { @class = "Details" })

jQuery

$(".Details").live(
    "click", function (e) {
    // e.preventDefault(); use this or return false
    var url = $(this).attr('href');

    $("#dialog-view").dialog({
        title: 'Detail User',
        autoOpen: false,
        resizable: false,
        height: 250,
        width: 400,
        show: {
            effect: 'drop',
            direction: "up"
        },
        modal: true,
        draggable: true,
        open: function (event, ui) {
            $(this).load(url);
        },
        buttons: {
            "Close": function () {
                $(this).dialog("close");
            }
        },
        close: function (event, ui) {
            $(this).dialog('close');
        }
    });

    $("#dialog-view").dialog('open');

    return false;

    e.preventDefault();

});

我在实体框架中开发。

感谢您的帮助!

【问题讨论】:

  • 我认为您需要查看部分视图
  • .live() --> 不推荐使用的版本:1.7,删除:1.9

标签: jquery asp.net-mvc razor webforms entity-framework-5


【解决方案1】:

返回 PartialView 而不是 View

public PartialViewResult Details(int id)
        {
            User user = context.User.Single(x => x.UserId == id);
            return PartialView("Details", user);
        }

【讨论】:

  • WannaCSharp,不工作。 public PartialViewResult Details(int id) { User user = context.User.Single(x => x.UserId == id);返回部分视图(用户); }
  • WannaCSharp,同样的结果。
  • 成功了!谢谢大家。
猜你喜欢
  • 1970-01-01
  • 2013-08-12
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-24
相关资源
最近更新 更多