Greetings, i would like to prepare some good "machine" for calling asp.net mvc methods from jquery. The concept is as follows:
The concept is to have a one method each requests will be calling. By using visitor pattern I will be able to determine what kind of operation i should do.
public interface IRequestVisitor
{
void VisitRequest_GetPersons(CRequest_GetPersons request);
void VisitRequest_RemovePerson(CRequest_RemovePerson request);
}
Creating some abstract request:
public abstract class CRequest
{
public abstract void AcceptVisitor(IRequestVisitor visitor);
}
and the implementation of concrete request:
public class CRequest_GetPersons: CRequest
{
public CRequest_GetPersons(Guid schoolROWGUID)
{
SchoolROWGUID = schoolROWGUID;
}
public Guid SchoolROWGUID={get;private set;}
public override void AcceptVisitor(IRequestVisitor visitor)
{
visitor.VisitRequest_GetPersons(this);
}
}
And the implemetation of visitor:
public void CRequestVisitor : IRequestVisitor
{
public CResponse ResponseResult {get;private set;}
public void IRequestVisitor.VisitRequest_GetPersons(CRequest_GetPersons request)
{
//code responsible for getting persons
Result = new CResponse_GetPersons_Success(List<Person>)
}
public void VisitRequest_RemovePerson(CRequest_RemovePerson request)
{
//code responsible for removing person
Result = new CResponse_RemovePerson_Success();
}
}
The action each js methods will execute is as follows:
public ActionResult AjaxRequest(CRequest request)
{
CRequestVisitor visitor = new CRequestVisitor();
request.AcceptVisitor(visitor);
return JSON(visitor.Result);//return some result
}
I have also found how asp.net mvc methods can be called using jquery
<script type="text/javascript">
$(document).ready(function() {
$("#GetPerson").click(function() {
$.getJSON("/Test/Request",
function(data){
//what should be here to display all persons ?
//how can i pass guid of school?
});
});
});
});
</script>
I would like to know how can I pass the rowguid of currently selected school. And how can I access list of persons returned as JSON object?