Assume I have two actions methods action1 and action2:
Action1:
public JavaScriptSerializer action1()
{
var student = new Student() { First = "john", Last = "doe" };
JavaScriptSerializer jsonStudent = new JavaScriptSerializer();
jsonStudent.Serialize(student);
return jsonStudent;
}
Action2:
public void action2()
{
var student = new Student() { First = "john", Last = "doe" };
JavaScriptSerializer jsonStudent = new JavaScriptSerializer();
jsonStudent.Serialize(student);
Response.Write(jsonStudent);
}
Assume my view has a Ajax call like this:
<script>
$(function () {
$.ajax({
url: 'AjaxCallsTest/action1',
dataType: 'json',
success: function (response) {
//code here
},
error: function (response, status, xhr) {
//code here
}
})
})
</script>
In the two cases one was written to Response object and the other has a return statement. my question even when there is a return, does it actually adds the jsonStudent object to the Response object if so writing action methods with return statements are meaningless?
Thanks.
Aucun commentaire:
Enregistrer un commentaire