Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return an XML string as an action result in MVC [duplicate]

Possible Duplicate:
What is the best way to return XML from a controller's action in ASP.NET MVC?

I'm able to return JSON and partial views (html) as a valid ActionResult, but how would one return an XML string?

like image 469
Toran Billups Avatar asked May 18 '09 16:05

Toran Billups


People also ask

How can I return string result from action in ASP NET MVC?

You can't return a string from a method which returns an ActionResult, so in this case you return Content("") as swilliams explained. If you only ever need to return a string, then you would have the method return a string, as Phil explained.

What is action result method in MVC?

An action result is what a controller action returns in response to a browser request. The ASP.NET MVC framework supports several types of action results including: ViewResult - Represents HTML and markup. EmptyResult - Represents no result.


1 Answers

You could use return this.Content(xmlString, "text/xml"); to return a built XML string from an action.

like image 155
John Downey Avatar answered Sep 18 '22 01:09

John Downey