阿贾克斯的WebGrid ..如何使它与MVC 4 W /剃刀工作剃刀、使它、工作、阿贾克斯

2023-09-11 01:12:26 作者:一身傲娇气

我开始工作的WebGrid与MVC 4,我能够显示分页/分类及其工作按预期....如果我尝试与阿贾克斯那么它拼尽了全力后做出来。

查看 - 管窥:(_hostajax.cshtml)

  @model IEnumerable的< issoa_ef.host>
@ {
    ViewBag.Title =指数;
}
< H2>指数< / H>
&其中p为H.;
    @ Html.ActionLink(新建,创建)
&所述; / P>

    @ {
        VAR电网=新的WebGrid(
            模型,rowsPerPage:2,
            defaultSort:HostFirstName,ajaxUpdateContainerId:ajaxgrid);
    }

< D​​IV ID =ajaxgrid>
    @ grid.GetHtml(
                TABLESTYLE:gridTable
                headerStyle:gridHead
                footerStyle:gridFooter
                rowStyle:gridRow
                alternatingRowStyle:gridAltRow
        列:grid.Columns
        (
            grid.Column(HostFirstName,标题:名,格式为:@<文本> @ Html.ActionLink((串)item.HostFirstName,详细资料,主机,新{ID = item.HostId} ,NULL)< /文>)
                            grid.Column(HostMiddleName,标题:中间名),
                            grid.Column(HostLastName,标题:姓),
                            grid.Column(HostEmailAddress,标题:电子邮箱地址)
                        )
        )
< / DIV>
 

控制器:

 公众的ActionResult指数()
    {
        VAR模型= db.host.ToList();
        如果(Request.IsAjaxRequest())
            返回PartialView(_ hostajax,模型);
        其他
            返回查看(模型);
    }
 
4连胜出线 荷甲锋霸4场独造9球,欧冠比肩莱万,1纪录反超德罗巴

索引页:

 < H2> @ ViewBag.Message< / H>
&其中p为H.;
    @ Html.ActionLink(请求部署,CreateDeployment)
&所述; / P>
@ Html.Partial(_ hostajax,模型)
 

解决方案

我做了一个类似的应用。网格没有使用AJAX,但只得到方法来切换页面。这件事发生COS电网的JavaScript是打破用jQuery是没有定义的错误。当我加入了jQuery网格开始使用AJAX。

看MVC 4的WebGrid和jQuery产生两个错误。 jQuery是未定义后Ajax模型的变化的一种错误jQuery是未定义错误。

I started working on WebGrid with MVC 4 and I able to display the paginating/sorting and its work as expected.... if i try to make it with with ajax then its doing the full post.

View: - Partial View: (_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>

Controller:

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

Index page:

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

解决方案

I've made a similar application. The grid was not using ajax, but just GET method to switch pages. This happened cos grid's javascript was breaking with "jquery is not defined" error. When I added the jQuery the grid started using ajax.

see MVC 4 WebGrid and Jquery produces two errors. JQuery is undefined and a sort error after ajax model change for the "jquery is not defined" error.

 
精彩推荐
图片推荐