【问题标题】:WebGrid Ajax.. how to make it work with MVC 4 W/RazorWebGrid Ajax .. 如何使其与 MVC 4 W/Razor 一起使用
【发布时间】:2013-09-13 06:44:35
【问题描述】:

我开始使用 MVC 4 开发 WebGrid,并且能够按预期显示分页/排序及其工作....

视图:- 部分视图:(_hostajax.cshtml)

@model IEnumerable<issoa_ef.host>
@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
    @Html.ActionLink("Create New", "Create")
</p>

    @{  
        var grid = new WebGrid(
            Model, rowsPerPage: 2,
            defaultSort: "HostFirstName", ajaxUpdateContainerId: "ajaxgrid");
    }

<div id="ajaxgrid">
    @grid.GetHtml(
                tableStyle: "gridTable",
                headerStyle: "gridHead",
                footerStyle: "gridFooter",
                rowStyle: "gridRow",
                alternatingRowStyle: "gridAltRow",
        columns: grid.Columns
        (
            grid.Column("HostFirstName", header: "First Name", format: @<text>@Html.ActionLink((string)item.HostFirstName, "Details", "Host", new { id = item.HostId }, null)</text>),
                            grid.Column("HostMiddleName", header: "Middle Name"),
                            grid.Column("HostLastName", header: "Last Name"),
                            grid.Column("HostEmailAddress", header: "eMail Address")
                        )
        )
</div>

控制器:

    public ActionResult Index()
    {
        var model = db.host.ToList();
        if (Request.IsAjaxRequest())
            return PartialView("_hostajax", model);
        else
            return View(model);
    }

索引页面:

<h2>@ViewBag.Message</h2>
<p>
    @Html.ActionLink("Request Deployment", "CreateDeployment")
</p>
@Html.Partial("_hostajax", Model)

【问题讨论】:

  • 你所说的“做完整的帖子”是什么意思?当你测试 ajax 时,代码是否进入 PartialView() 行?

标签: ajax c#-4.0 asp.net-mvc-4 razor webgrid


【解决方案1】:

我做了一个类似的申请。网格没有使用 ajax,而只是 GET 方法来切换页面。这发生了因为网格的 javascript 因“未定义 jquery”错误而中断。当我添加 jQuery 时,网格开始使用 ajax。

请参阅 MVC 4 WebGrid and Jquery produces two errors. JQuery is undefined and a sort error after ajax model change 了解“未定义 jquery”错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2012-11-01
    • 2019-05-06
    • 2015-09-24
    • 2013-05-22
    相关资源
    最近更新 更多