jQuery calling an action

1

I'm developing a web site in ASP.NET MVC that uses jquery to control some plugins like spinner, toastr and others. My question is if I should call Action via jquery to validate the model and within Action make a call rest (which was built in api web ) and return the response in the javascript function.

As I worked a lot with mobile, most of the calls were made on the client, and in this case I see that the call is being made inside the controller , in this case, on the server.

    
asked by anonymous 13.09.2015 / 00:56

1 answer

2
  

My question is whether to call Action via jquery to validate the model and Action make a call rest (which was built in web api) and return the response in the javascript function.

Web API is a great place to do this, but it's good to make sure that the request header explicitly requests a JSON:

$.ajax({
    dataType: ($.browser.msie) ? "text" : "json",
    accepts: {
        text: "application/json"
    },
    ...
});

It can be done in ASP.NET MVC too, but do not use ActionResult to declare Action . Use:

public JsonResult MinhaAction() { ... }
    
26.09.2016 / 17:02