Well, thanks for your help. What I was looking for was a complete answer. For the sake of other n00bs who might have a similar question, here IS the complete answer.
In the View:
<script type="text/javascript">
function DoneWithTest()
{
var selected = $("input:radio:checked");
var selArray = new Array();
for (var a=0; a< selected.length; a++)
{
selArray.push(selected[a].value);
}
$.ajax({
url: '../../Test/FinishedTest',
data: JSON.stringify(selArray),
type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result) {
},
error: function ()
{
alert("error");
}
});
}
</script>
and in the Controller:
public ActionResult FinishedTest(List<string> selArray)
{
//do something with data
return View("Index");
}
It's a little disconcerting that an action like this, which would seem to me, to be a very commonplace occurence, should have such a lack of instructions. I searched many sites looking for a simple answer to what I felt was a simple question, and really
never found what I was looking for. I urge all of my colleagues to, when encountering this situation, post clear concise examples for the benfit of others in the community. Again, thanks for your help.
Marked as answer by vinceweeks on Apr 27, 2012 02:14 AM
vinceweeks
0 Points
18 Posts
Re: "post" ing json data to a controller method
Apr 27, 2012 02:13 AM|LINK
Well, thanks for your help. What I was looking for was a complete answer. For the sake of other n00bs who might have a similar question, here IS the complete answer.
In the View:
<script type="text/javascript"> function DoneWithTest() { var selected = $("input:radio:checked"); var selArray = new Array(); for (var a=0; a< selected.length; a++) { selArray.push(selected[a].value); } $.ajax({ url: '../../Test/FinishedTest', data: JSON.stringify(selArray), type: 'POST', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (result) { }, error: function () { alert("error"); } }); } </script>and in the Controller:
public ActionResult FinishedTest(List<string> selArray) { //do something with data return View("Index"); }It's a little disconcerting that an action like this, which would seem to me, to be a very commonplace occurence, should have such a lack of instructions. I searched many sites looking for a simple answer to what I felt was a simple question, and really never found what I was looking for. I urge all of my colleagues to, when encountering this situation, post clear concise examples for the benfit of others in the community. Again, thanks for your help.