How to return xml response from controller's action in asp.mvc?

beginer
beginer
1576 Points
53 Posts

I'm trying to generate rss/feed xml response in an ASP.MVC application. What is the best way to return XML from a controller's action in ASP.NET MVC? There is a nice way to return JSON, but not for XML. I need to do something like

public class FeedController : Controller
    {
        public ActionResult Index()
        {
            return xml("<xmlstring>", "text/xml", System.Text.Encoding.UTF8);
        }
    }
Views: 1825
Total Answered: 1
Total Marked As Answer: 0
Posted On: 05-Oct-2022 00:07

Share:   fb twitter linkedin
Answers
Stevan
Stevan
312 Points
20 Posts
         

You can use:

return this.Content(xmlString, "text/xml");

to return xml response from action with xml string.

 

Posted On: 05-Oct-2022 00:45
 Log In to Chat