This is a migrated thread and some comments may be shown as answers.

Close pop windows after upload file

2 Answers 23 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Gregoryy
Top achievements
Rank 1
Gregoryy asked on 08 Aug 2011, 10:51 PM
Hi telerik and thank for your product!

I created pop windows form form for add news at site. Form  have how control text and to upload file control. Upload file control for news picture. After add news I try close this window and refresh grid.

[HttpPost]
        public ActionResult Add(NewsGrid news, HttpPostedFileBase img)
        {
            if (string.IsNullOrEmpty(news.TitleTranslit))
            {
                news.TitleTranslit = news.Title.ToTranslit();
            }
 
            news.AuthorPublish = UserInfo.Name;
 
            if (ModelState.IsValid)
            {
                this.GridNewsRepository.InsertOrUpdate(news);
                string fileName = string.Format("short-{0}", news.Id);
                string getFileName;
                this.SaveNewsImage(img, fileName, out getFileName);
                var imaeg = new ImageNews { Id = news.Id, NewsImage = getFileName };
                this.NewsImageRepository.InsertOrUpdate(imaeg);
                return JavaScript("$('#NewsGrid').data('tGrid').ajaxRequest();$('.t-window').data('tWindow').close();");
            }
 
            return View(news);
        }
But my code $('#NewsGrid').data('tGrid').ajaxRequest();$('.t-window').data('tWindow').close(); return how text :(

2 Answers, 1 is accepted

Sort by
0
Igniter
Top achievements
Rank 1
answered on 11 Aug 2011, 03:04 PM
Try with jquery post. On controller just return Content("") (or "false" and show errors or make client verification). 
Something like this (just example):
$('#yourform').submit(function() { 
    var form = $(this).serialize()
    $.post('/News/Add', form,  function(data) {
        $('#NewsGrid').data('tGrid').ajaxRequest();
        $('#yourFormWindow').data('tWindow').close();
    });
});


0
Gregoryy
Top achievements
Rank 1
answered on 11 Aug 2011, 09:41 PM
Thank but I made little other
$('#addnewsform').submit(function () {
       $(this).ajaxSubmit({ beforeSubmit: ajaxValidate, target: "#sectedit", success: success });
       return false;
   });
 
   $("#btncancel").click(function () {
       $('.t-window').data('tWindow').close();
       return false;
   });
 
   function success() {
       $('#NewsGrid').data('tGrid').ajaxRequest();
       $('.t-window').data('tWindow').close();
   }
 
   function ajaxValidate() {
       return $('#addnewsform').validate().form();
   }
Tags
General Discussions
Asked by
Gregoryy
Top achievements
Rank 1
Answers by
Igniter
Top achievements
Rank 1
Gregoryy
Top achievements
Rank 1
Share this question
or