0 Replies - 460 Views - Last Post: 21 February 2015 - 03:05 PM

#1 sela007   User is offline

  • D.I.C Addict

Reputation: 139
  • View blog
  • Posts: 841
  • Joined: 21-December 11

data posted to mvc app controller via winforms is always null

Posted 21 February 2015 - 03:05 PM

this is winforms method
private void NewUser()
        {
            string dataToSend ="newUser=" +  CurrentUser.GetJson();   
            string loginUrl = "http://localhost:56874/Home/NewUser";
            var dataBytes = System.Text.Encoding.UTF8.GetBytes(dataToSend);
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(loginUrl);
            //req.ContentType = "application/json";
            req.ContentLength = dataBytes.Length;
            req.Method = "POST";
            using (var stream = req.GetRequestStream())
            {
                stream.Write(dataBytes, 0, dataBytes.Length);
            }

            // -- execute request and get response
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
           
        }


and this is mvc controller method
        [HttpPost]
        public void NewUser(string  newUser)
        {
           '...

        }

but value newUser is always null.
can someone please help me and show me what I'm doing wrong?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1