Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There's a few issues with your code. First, despite the fact that you're passing a parameter <code>zone</code> to the web service method the method itself doesn't receive this parameter. Second, if you want to return JSON don't use the return type string. Use <code>JSONResult</code>. This will allow you to remove the static keyword as well. I'd recommend changing your method like so:</p> <pre><code>public JSONResult GetCountry(int? zone) { // ... } </code></pre> <p>There are two final changes you should make. The first is to use ASP.Net MVC's built in <code>Json()</code> method to handle serialization of your object. The second is that you should always project your data layer results even if they happen to already be in the structure you want to use. This way if you change your data layer object in a way that breaks the service you'll get a compile error instead of a run time exception.</p> <pre><code>return Json(from c in Countries.GetAll() select new { Id = c.Id, Name = c.Name }) </code></pre> <p>I'd also recommend avoiding using <code>$.get</code> or <code>$.post</code> as they abstract away settings that can be useful when access web services. If you want to shorthand it I'd recommend wrapping the <code>$.ajax</code> call in your own function. You're also going to want to think about standardizing your web service responses. Your web service is a protocol of sorts and as such it benefits from having a well defined header. For a more in-depth explanation take a look here: <a href="http://www.netortech.com/Blog/Entry/17/MVC-Service-Based-Web-Applications---Part-I---Introduction" rel="nofollow">Introduction to MVC Service Based Web Applications</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload