Answer the question
In order to leave comments, you need to log in
Send collection of data to ASP.NET MVC Action via jQuery post to different domain?
Hey !
I created an index.html file on the C:\ drive, then in the file I wrote a simple post request via $.post() that sends an array with data to the url: localhost:1901/Test/AddWords . On the ASP.NET MVC server, an application that runs locally url: localhost:1901 on the AddWords action of the Test controller.
In action, the array comes only with empty element fields.
Code from html file.
The file is just in a folder on the computer.
//index.html
$.post("http://localhost:1901/Test/AddWords",{words:words},function(data){
});
public ActionResult AddWords(Word [] words)
{
//words[0].Translation = null;
}
Answer the question
In order to leave comments, you need to log in
I redid it like this
public ActionResult AddWords()
{
var wordsModel = HttpContext.Request.Form["words"];
var wordArray = new JavaScriptSerializer().Deserialize<WordModel[]>(wordsModel);
}
The fields are empty because the model binding does not work. Domains have nothing to do with it.
It looks terrible, but I think the essence is clear:
$.post("http://localhost:1901/Test/AddWords", {
"words[0].id" : 123,
"words[0].EngValue" : 123123,
"words[0].Translation" : 123123,
}, function (data) {
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question