Paul
Paul

Reputation: 5924

Using jQuery ajax call in Asp.Net

I am somewhat new to ASP. I want to make an ajax call, but I cannot figure our the URL to send to. What on earth is the actual URL to the application? Of course it comes up as http:// localhost : someport/ (spaces added because the link violates SO questions) in the browser. When I try typing in ["index","default"].["asp","aspx","htm","html","asm","asmx"] afterwards I get an error.

The relevant JavaScript portion looks like this:

$.ajax({
   "url": "Default.aspx/ProcessReq",

And the relevant C# code in my controller looks like:

[WebMethod]
public object ProcessReq(string s) {

I have added the following to the config file:

<configuration>
   <system.web>
      <webServices>
        <protocols>
           <add name="HttpGet"/>
           <add name="HttpPost"/>
         </protocols>
      </webServices>
   </system.web>
</configuration>

I'm sure I am doing something completely wrong, and I'll stress once again that ASP is fairly new to me. Any ideas?

Upvotes: 0

Views: 275

Answers (1)

Dave Alperovich
Dave Alperovich

Reputation: 32490

Seems like you are coming to MVC with Web Forms still fresh in your mind. That's common.

Unfortunately MVC is very different than WebForms. You would NOT be calling Views (aspx or razor) directly. You call you Action Method: /home/index ... and the default.aspx can be left out. try it.

ActionResult is base class of response types returned by Controller Actions

public ActionResult ProcessReq()
{
    return View(model)
}

or your ProcessReq can be of Json type

public ActionResult ProcessReq()
{
    Json(new { page= "<HTML></HTML>", control= "<input type='text' id='control'>" });
}

Action Results can return Views', PartialView's and JSon (among many other possibilities). In this case you have to decide which of these response types you want, depending on the implementation requirements of your design.

Upvotes: 1

Related Questions