Hi,
[b]I need to show a message after the creation of record using ajax callback. The text of message is made in mvc controlller.[/b]
My controler is simply:
[code] [HttpPost]
public ActionResult User_Create([DataSourceRequest] DataSourceRequest request, UserRoleModel model)
{
if (model != null && ModelState.IsValid)
try
{
new LoginCommand().CreateUserData(model, UserSession, ref myMessage);
}
catch (Exception exception)
{
ModelState.AddModelError("", exception.Message);
}
return Json(new[] { model }.ToDataSourceResult(request, ModelState));
}
[/code]
The interface in razor looks like this
[code] @(Html.Kendo().Grid(Model).Name("UzytkownicyGrid")
.Columns(cols =>
{
cols.Bound(p => p.UserLogin).Width(150).Locked();
cols.Bound(p => p.UserName).Width(200);
// cols.Bound(p => p.Status).Width(60);
cols.Bound(p => p.Active).ClientTemplate("#=Active ? 'Tak': 'NIE'#").Width(80);
if (WlasneCommonFunc.IsAdministrator(ViewData))
{
cols.Command(command => command.Edit().Text("edytuj")).Width(120);
}
cols.Bound(p => p.MailAddress).Width(200).ClientTemplate("#= createMailLink(MailAddress) #");
cols.ForeignKey(p => p.RoleId, (IEnumerable)ViewData["roles"], "IdRoli", "Summary")
.Title("Uprawnienia").Width(150).MinScreenWidth(900);
cols.Bound(p => p.Mobilephone).Width(100).MinScreenWidth(1000).ClientTemplate("#= createPhoneLink(Mobilephone) #");
cols.Bound(p => p.Telephone).Width(100).MinScreenWidth(1100).ClientTemplate("#= createPhoneLink(Telephone) #");
cols.Bound(p => p.Funkcja).Width(100).MinScreenWidth(1200);
cols.Bound(p => p.MailDw).Width(200).MinScreenWidth(1300).ClientTemplate("#= createMailLink(MailDw) #");
})
.Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("UzytkownicyEdit").Window(w => w.Title("Korekta uprawnieĊ").Width(400)))
.Groupable()
.Resizable(resize => resize.Columns(true))
.Reorderable(reorder => reorder.Columns(true))
.Sortable()
.Filterable()
.ToolBar(toolbar =>
{
if (WlasneCommonFunc.IsAdministrator(ViewData))
{
toolbar.Create();
}
})
.Navigatable()
.Events(e => e.Edit("uzytkownikEdit"))
.DataSource(dataSource => dataSource
.Ajax()
.ServerOperation(false)
.Model(model => model.Id(p => p.Identity))
.Events(events => events.Error("errorHandler"))
.Read("Uzytkownicy_Read", "Profil")
.Update("Uzytkownicy_Update", "Profil")
.Create("Uzytkownicy_Create", "Profil")
.Group(groups => groups.Add(p => p.RoleId))
))
[/code]
With displaying errors I have no problems.They are showed by the following function
[code]function errorHandler(e) {
if (e.status = "error") {
var message = "OPERACJA NIEUDANA\n";
if (e.errors) {
$.each(e.errors, function(key, value) {
if ('errors' in value) {
$.each(value.errors, function() {
message += this + "\n";
});
}
});
} else
message += e.errorThrown;
alert(message);
}
}
[/code]
What method is the best to do with it? Please help me out.
Regards,
Josef Jaskowiec
Rekord