如何在不使用Jquery的情况下在MVC中的ajax.beginform调用上将WebGrid()数据发布到控制器

时间:2018-06-13 11:17:16

标签: asp.net-mvc

这是我的观点,它显示网格数据,但是当我点击保存按钮时,它不会将网格数据发布到控制器,我怎么能将它发布到控制器

@using DataEntities
@model SettlementProcess 
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    ViewBag.Header = "Settlement Process";

    var grid = new WebGrid();

    grid = new WebGrid(Model.BuyTradeSettlement, canPage: false, canSort: false, rowsPerPage: 30);

    AjaxOptions optSave = new AjaxOptions
    {
        HttpMethod = "POST",
        OnBegin = "BuyTradeGrid",
        InsertionMode = InsertionMode.Replace,
    };

}

<div class="container">
    <div class="form-group">
        PROCESS DATE: <b>@string.Format("{0:dd MMMM yyyy}", Model.EODDate)</b>
    </div>
    <div class="form-group">
        TRADE DATE(S) FOR SETTLEMENT: <b>@string.Format("{0:dd MMMM yyyy}", Model.TradeSettlementDate)</b>
    </div>


    <div id="BuyTradeGrid" style="display:block;">


            @if (Model.BuyTradeSettlement != null)
            {



                @grid.GetHtml(
                              tableStyle: "gridCss",
                     alternatingRowStyle: "altRow", rowStyle: "alt", selectedRowStyle: "select",
                     mode: WebGridPagerModes.All,
                                    htmlAttributes: new { id = "MainGrid" },
                     firstText: "<< First",
                     previousText: "< Previous", nextText: "Next >",
                     lastText: "Last >>",


                    columns: grid.Columns(
                    grid.Column(columnName: "Client Code", format: item => Html.Raw("<span>" + item.CLIENT_CODE + "</span>")),
                    grid.Column(columnName: "Client Name", format: item => Html.Raw("<span>" + item.CLIENT_NAME + "</span>")),
                    grid.Column(columnName: "Trade Date", format: item => Html.Raw("<span>" + item.TRADE_DATE + "</span>")),
                    grid.Column(columnName: "ISIN", format: item => Html.Raw("<span> " + item.ISIN + "</span>")),
                    grid.Column(columnName: "Name", format: item => Html.Raw("<span> " + item.NAME + "</span>")),
                    grid.Column(columnName: "Exchange", format: item => Html.Raw("<span> " + item.EXCHANGE + "</span>")),
                    grid.Column(columnName: "Traded Quantity", format: item => Html.Raw("<span>" + item.TRADED_QUANTITY + "</span>")),
                    grid.Column(columnName: "Pay Out Quantity", format: item => Html.Raw("<span " + item.PAY_OUT_QUANTITY + "</span>")),
                    grid.Column(columnName: "Market Receivable", format: item => Html.Raw("<span>" + item.MARKET_RECEIVABLE + "</span>"))
                    )
                    )

                using (Ajax.BeginForm("Binddata", "SettlementProcess", Model, optSave))
                {
                    <div class="col-md-2">
                        <input type="submit" name="Command" id="btnFinalSave" class="btn btn-success btnFinalSave save-book" value="Save" />
                        <input type="submit" name="Command" id="btnFinalDelete" class="btn btn-warning btnFinalDelete delete-book" value="Delete" />
                    </div>
                }


            }
    </div>  

</div>

这是我的控制器操作方法,我想在保存按钮上获取数据点击我试过但它没有与模型绑定所有值都显示为空。

public ActionResult Binddata(SettlementProcess s)
{
    return Json(s, JsonRequestBehavior.AllowGet);
}

0 个答案:

没有答案