在mvc 3中的telerik网格中插入动作

时间:2013-01-06 19:12:50

标签: insert telerik grid

为什么当我点击网格中的插入按钮时,动作不会被调用。 我在行动中设置了断点但是没有调用动作。 这是我的行动:

[AcceptVerbs(HttpVerbs.Get)]
[GridAction]
public ActionResult _InsertAjaxEditing()
{
    return View();
}

[AcceptVerbs(HttpVerbs.Post)]
[GridAction]
public ActionResult _InsertAjaxEditing(Employee e)
{
    bus = new SysBusContext();
    string error = null;
    IEnumerable<Employee> emps = null;
    if (e != null)
        if (e.EmployeeId != null)
        {
            try
            {
                Employee emp = new Employee();
                emp = e;
                bus.Employees.Add(emp);
                bus.SaveChanges();
            }
            catch
            {
            }
        }
    emps = bus.Employees.ToList();
    return View("EmpSave", emps);
}

这是我的观点:

<div class="t-rtl">
@(Html.Telerik().Grid<TelerikMvcApplication3.Models.Employee>()
        .Name("Grid")
        .DataKeys(keys => 
        {
            keys.Add(p => p.EmployeeId);
        })
        .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).
            ImageHtmlAttributes(new {style="margin-Right:0"}))
        .DataBinding(dataBinding => 
        {
            dataBinding.Ajax()
                .Select("_SelectAjaxEditing", "CtrlEmployee")
                .Insert("_InsertAjaxEditing", "CtrlEmployee")
                .Update("_SaveAjaxEditing", "CtrlEmployee")
                .Delete("_DeleteAjaxEditing", "CtrlEmployee");
        })
        .Columns(columns =>
        {
            columns.Bound(p => p.EmployeeId).Width(95);
            columns.Bound(p => p.FirstName).Width(50).Sortable(true);
            columns.Bound(p => p.LastName).Width(50).Sortable(true);
            columns.Bound(p => p.Recruitment).Width(70);//.ClientTemplate(@Html.Telerik().DatePicker();
            columns.Bound(p => p.Email).Width(100).Format("{0:d}");
            columns.Bound(p => p.PhoneNumber).Width(65);
            columns.Bound(p => p.Type).Width(50);
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.ImageAndText);
                commands.Delete().ButtonType(GridButtonType.ImageAndText);
            }).Width(180).Title("ویرایش");
        }).ClientEvents(e => e
            .OnDataBinding(
                @<text> function(a) { a.data = $.extend(a.data,{ dropdownlist: $('#dropdownlist').val()}); }
                </text>)
            )
            .Editable(t => t.Mode(GridEditMode.PopUp))
        .Pageable()
        .Scrollable()
        .Sortable()     
)

</div>


@section HeadContent 
{
<style type="text/css">

    .t-widget, .t-widget .t-input, .t-widget .text-box, .t-button {
    font-family: tahoma;
    font-size: 100%;
    }


    .field-validation-error
    {
        position: static;
        right: 50px;
        top: -15px;
    }

    * html .field-validation-error { position: relative; }
    *+html .field-validation-error { position: relative; }

    .field-validation-error span
    {
        position: absolute;
        white-space: nowrap;
        color: red;
        padding: 17px 5px 3px;
        background: transparent url('@Url.Content("~/Content/Common/validation-error-message.png") ') no-repeat 0 0;
    }

    /* in-form editing */
    .t-edit-form-container
    {
        width: 460px;
        margin: 1em;

    }

    .t-edit-form-container .editor-label{ float: right;}
    .t-edit-form-container .editor-field
    {
        padding-bottom: 1em;
        float: right;
    }

    .t-edit-form-container .editor-label
    {
        width: 30%;
        text-align: right;
        padding-right: 3%;
        clear: right;
    }

    .t-edit-form-container .editor-field
    {
        width: 60%;
        font:
    }

     #GridPopUp
        {
            position:fixed;
            top:10px;
            }

</style>

1 个答案:

答案 0 :(得分:0)

尝试删除此

--> [AcceptVerbs(HttpVerbs.Get)]  - 
[GridAction]
public ActionResult _InsertAjaxEditing()
{
   return View();
}

也许请求是POST

尝试删除此

[AcceptVerbs(HttpVerbs.Get)]  - 
--> [GridAction]
public ActionResult _InsertAjaxEditing()
{
   return View();
}