【问题标题】:How to pass value from kendo grid to kendo window in MVC如何将值从剑道网格传递到 MVC 中的剑道窗口
【发布时间】:2016-06-26 02:37:31
【问题描述】:

如何在网格的按钮单击事件中将选定行的 PreEmploymentId 从网格传递到窗口。这可能很简单,但我是新手,还在学习基础知识。

脚本-

<script>
    $("[data-button-type='auction']")
                .click(function(e) {
                    myWindow.data("kendoWindow").open();
                    myWindow.data("kendoWindow").center();
                    myWindow.data("kendoWindow").top();
                });
</script>

剑道网格-

<div >
@*Telerik grid*@
@{
    Html.Kendo().Grid(Model.LstPreEmploymentWorkflowModellist)
        .Name("MyGrid")
        .Columns(col =>
        {
            //on edir button click action name Main in invoked in PreEmploymentWorkflow controller and PreEmploymentId is passed
            col.Template(@<text>
                             @Html.ActionLink("Edit", "Main", "PreEmploymentWorkflow", new {Id = item.PreEmploymentId}, new {@class = "classname"})</text>).Width(30);
            col.Bound(o => o.PreEmploymentId).Visible(false).Groupable(false);
            col.Bound(o => o.FirstName).Width(30).Groupable(false);
            col.Template(@<text>
                             @Html.ActionLink("OpenFile", "Openfile", "PreEmploymentWorkflow", new {Id = item.PreEmploymentId, uploadfilename = "EEOC Tracking Form"}, new {@class = "classname3"})</text>).Title("EEOC").Width(30);
            col.Template(@<text>@(Html.Kendo().Button()
                                      .Name("open" + @item.PreEmploymentId)
                                      .ImageUrl(Url.Content("/images/auction_16.gif")).HtmlAttributes(new {type = "submit", data_button_type = "auction" })
                                      )
                          </text>).Width(40).Title("Status");
            col.Template(@<text>
                             @Html.ActionLink("Delete", "Delete", "PreEmploymentWorkflow", new {Id = item.PreEmploymentId}, new {@class = "classname2"})</text>).Width(30);
        })
        //.HtmlAttributes(new { style = "width: 1100px" })
        .Sortable()
        .Render();
}

剑道窗口-

 @{Html.Kendo().Window()
      .Name("window")
      .Width(500)
      .Height(315)
      .Animation(true)
      .Draggable()
      .Visible(false)
      .Modal(true)
      .Title("Employment Status")
      .Actions(actions => actions.Close())
      .Content(@<text>
                   @using (Html.BeginForm("CreateStatus", "PreEmploymentWorkflow", FormMethod.Post, new { enctype = "multipart/form-data" }))
                   {
                       <table>
                           <tr>
                           <td>
                                   @(Html.Kendo().TextBoxFor(m => m.LstPreEmploymentWorkflowModel.PreEmploymentId))
                               </td>
                               <td>
                                   @(Html.Kendo().RadioButtonFor(m => m.LstPreEmploymentWorkflowModel.Status).Value(1).Label("Approved"))
                               </td>
                               <td>
                                   @(Html.Kendo().RadioButtonFor(m => m.LstPreEmploymentWorkflowModel.Status).Value(9).Label("Reject"))
                               </td>
                           </tr>
                           <tr>
                               <td>
                                   <label class="Bold" for="statusattachment">Status Attachment:</label>
                               </td>
                               <td><input type="file" name="uploadfilestatus"/></td>
                           </tr>
                           <tr>
                               <td>
                                   <input id="Button1" type="submit" value="Submit"/>
                               </td>
                           </tr>
                       </table>
                   }
                </text>)
      .Render();
}

提前致谢。

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    如果有人在搜索,该怎么做

    <script>
    
    function editItem(e) {
        e.preventDefault();
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        var pId = dataItem.PreEmploymentId;
    
    
           var myWin = $("#windowstatus").kendoWindow({
    
            modal: true,
            width: "450px",
            height: "250px",
            resizable: true,
            position: {
                top: 400,
                left: 650
            },
            title: "PreEmployment Status",
            content: {
                url: "../StatusWindow", //controller name
                data: { customerId: pId } //passing data
            }
    
        });
        myWin.data("kendoWindow").open();
        return false;
    }
    </script>
    
    <script type="text/x-kendo-template" id="template">
        <div id="details-container">
    
        </div>
    </script>
    

    在剑道网格中,

        col.Bound(o => o.PreEmploymentId).Visible(false).Groupable(false);
        col.Command(command => command.Custom("Change Status").Click("editItem")).Width("120px");
    

    在 StatusWindowController 中,

    public class StatusWindowController : Controller
        {
            // GET: StatusWindow
            public ActionResult Index(int customerId)
            {
    
                return View(mixstatus);
            }
        }
    

    【讨论】:

      【解决方案2】:

      这个演示正好展示了这一点:

      http://demos.telerik.com/aspnet-mvc/grid/custom-command

      【讨论】:

      • 感谢您的回复。我按照给定的方式尝试过,但它是以 html 格式给出的。我希望它成为模型的对象,以便我可以将按钮单击事件的值传递到数据库中。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多