Getting custom message from controller

3 posts, 0 answers
  1. Janusz
    Janusz avatar
    12 posts
    Member since:
    Jul 2012

    Posted 29 Dec 2015 Link to this post


    [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)
                        new LoginCommand().CreateUserData(model, UserSession, ref myMessage);
                    catch (Exception exception)
                        ModelState.AddModelError("", exception.Message);
                return Json(new[] { model }.ToDataSourceResult(request, ModelState));

    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")
                        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)))
                    .Resizable(resize => resize.Columns(true))
                    .Reorderable(reorder => reorder.Columns(true))
                    .ToolBar(toolbar =>
                        if (WlasneCommonFunc.IsAdministrator(ViewData))
                    .Events(e => e.Edit("uzytkownikEdit"))
                    .DataSource(dataSource => dataSource
                        .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))

    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;

    What method is the best to do with it? Please help me out.

    Josef Jaskowiec


  2. Boyan Dimitrov
    Boyan Dimitrov avatar
    1728 posts

    Posted 04 Jan Link to this post


    My suggestion is to use the requestEnd event of the Kendo UI DataSource and to check if the type of the request is  "create" to show the message. 

    Boyan Dimitrov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET AJAX banner
  4. Janusz
    Janusz avatar
    12 posts
    Member since:
    Jul 2012

    Posted 07 Jan Link to this post

    Thanks a lot - this works fine. Here is my requestEndHandler code

    function requestEndHandler(evt) {
        if (evt.type === "create") {
            var data = evt.response.Data[0];
  'Dane do logowania zostały wysłane na adres: ' + data.MailAddress);


Back to Top