This is a migrated thread and some comments may be shown as answers.
Insert Toolbar command not firing controller
2 Answers 35 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jamie
Top achievements
Rank 1
Jamie asked on 23 May 2012, 09:25 PM

I am new to MVC and cannot figure out why the controller to insert is not being fired.  I am posting my code in the hopes that someone can help.

VIEW:

 

@Html.Telerik().Grid<AnswerOptionViewModel>()

 .Name("AnswerOptions")

.DataKeys(k => k.Add(o => o.ID))

.ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText).ImageHtmlAttributes(new { style = "margin-left:0" }))

.DataBinding(dataBinding => dataBinding.Ajax()

.OperationMode(GridOperationMode.Client)

 .Select("_AnswerOptionsAjax", "Attribute", new { id = Model.ID })
.Update("_AnswerOptionsUpdateAjax", "Attribute", new { attributeId = Model.ID })

.Delete("_AnswerOptionsDeleteAjax", "Attribute", new { id = Model.ID })

.Insert("_AnswerOptionsInsertAjax", "Attribute", new { id = Model.ID })

)

.Columns(columns =>

{

columns.Bound(m => m.AnswerAbbr);

columns.Bound(m => m.AnswerText);

columns.Bound(m => m.AnswerValue).Width(32);

columns.Bound(m => m.RelatedImageId)

.ClientTemplate("<img alt='<#= AnswerText #>' class='answer-option-icon' src='"

                    + Url.Action("AttributeAnswerOption", "ImageGenerator", new { id = Model.ID, index = 0 })

                    + "' />").Width(32);

columns.Bound(m => m.RelatedImage).Hidden();

columns.Bound(m => m.Ordinal).Hidden().HtmlAttributes(new { style = "display: none;" });})

.ClientEvents(c => c

.OnRowSelect("AnswerOptions_onRowSelect")

.OnDataBound("AnswerOptions_onDataBound")

)
.HtmlAttributes(new { @class = "t-widget t-grid grid-no-header grid-no-footer" })

.Selectable()

.Editable(e => e.Mode(GridEditMode.PopUp))

.ToHtmlString());

})

)

CONTROLLER:

[HttpPost]

[GridAction]

public ActionResult _AnswerOptionsInsertAjax(AnswerOptionViewModel model)

{

var answerOption = AnswerOptionViewModel.CreateBlank();

var newId = (Attribute.AnswerOptions.Count > 0) ? Attribute.AnswerOptions.Min(ao => ao.ID) - 1: -1;

if (newId > 0)

newId = -1;

answerOption.ID = newId;

answerOption.AnswerText = "[blank]";

if(TryUpdateModel(answerOption))

Attribute.AnswerOptions.Add(answerOption);

Attribute.Save();

return View(new GridModel(Attribute.AnswerOptions));

The Insert popup comes up and waits for user input, but upon clicking on the Insert button, nothing happens.  Can someone please tell me how to fix this problem?

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 25 May 2012, 10:27 AM
Hi,

 The code looks correct from first sight. Do you see any JavaScript errors when you click the "insert" button? Does editing records work as expected?

Regards,
Atanas Korchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
0
Ki Won
Top achievements
Rank 1
answered on 02 Aug 2012, 04:48 PM
I have same error too !!!

but, Some pc's all browser kinds working well,
and some pc's all browser kinds not working.

My version is "Extensions for ASP.NET MVC Q2 2012" open source version(2012.2.607).
Tags
Grid
Asked by
Jamie
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Ki Won
Top achievements
Rank 1
Share this question
or