P
P
pavelpasha2016-07-06 23:02:08
JavaScript
pavelpasha, 2016-07-06 23:02:08

ASP MVC 5. How to pass string to controller using POST method.?

AJAX:

var xml = "example";
function send(xml) {  //отправка данных на сервер
                $.ajax({
                    type: 'POST',
                    url: '/Home/Form',
                    data: xml,

                    success: function (responce) {
                        SaveToLocal("s",xml);// префикс s - sended
                        notification("Данные успешно отправлены", "success");
                    },
                    error: function (xhr, str) {
                        SaveToLocal("u",xml);// префикс u - unsended
                        notification("Подключение недоступно, данные сохранены в локальном хранилище","warning");
                        setTimeout(DelayResend, 30 * 1000);// функция отложенной отпраки с тайм аутом 30 сек.
                    }
                })

            };



Controller:
[HttpPost]
        public void Form(string xml)
        {


            string mydocpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);          
           using (StreamWriter outputFile = new StreamWriter(mydocpath + @"\WriteLines.txt"))

            outputFile.WriteLine(xml);



           // return View();
        }

Form should write a string to a file. The file is created, but it is empty. When transferring, the "success" block is executed - it means that there are no errors during transfer. But where is the line being lost?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
devian3000, 2016-07-07
@pavelpasha

It's worth trying that.
public void Form(string xmlString)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question