0

I wrote some code in webapi ValueConroller. When I try to execute it I'm getting JSON data which is by default saving to text file (IE 8.0), XML output when tried with Mozilla Firefox .

I am not sure how to display my List<country> which will be having list of countries and i am writing this method in value controller like

public IEnumarable<countrylist> getcounrty()
{
obj.method1().tolist(); // method1 will return list<country> where country is a class in my BLL
} 

I want the method output to be bonded with Dropdownlist . Becoz there is no VIEW is webapi I am confused how to do it

Any ideas are appreciated.

EDIT : konckout.js is a alternative ? my colleagues ad-viced me so any best alternative mates

4
  • Welcome...show what you've tried so far. Commented Mar 25, 2014 at 17:04
  • Your question is very unclear, can you try to add more information? Commented Mar 25, 2014 at 17:04
  • Is the browser asking you to open a file? Could you please show how you are returning the ActionResult from your controller method. Commented Mar 25, 2014 at 17:07
  • Big Daddy : well i tried little and i am confused with binding my output to display to end user ? Thinking using what ? Jeroen Vannevel :edited once plz check and let me know lrb: nope but when i tried with IE 8.0 initially asking to save later when i open a file its in JASON format but Mozilla directly displaying in XML format . BUT i need list in dropdownlist Commented Mar 25, 2014 at 17:17

1 Answer 1

3

Web API and MVC have different purposes.

The purpose of ASP.NET Web API is to build HTTP-based web services (also sometimes called REST services). Out of the box, it only supports

  • JSON
  • XML

although you can implement other formatters yourself, if you need to exchange data in another format. In theory, you could write a custom formatter to produce HTML, but there's no reason to do that.

If you need to produce HTML, then use ASP.NET MVC.

Sign up to request clarification or add additional context in comments.

5 Comments

nice explanation . any ideas on knockout.js linked to webapi output ?
That would probably work well; personally, I use AngularJS to build a SPA that consumes the HTTP API.
well apart from your explanation can you possibly show some links to understand WEBAPI consumption and dealing that webapi to anjular or knockout.js . Thank you
"Well actually" it supports text/plain and application/octet-stream out of the box too. :-)
@supercool I have an AngularJS sample code base here: github.com/ploeh/booking-web-ui It consumes an ASP.NET Web API.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.