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?