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

beginer
beginer
296 Points
83 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: 110
Total Answered: 1
Total Marked As Answer: 0
Posted On: 05-Oct-2022 00:07

Share:   fb twitter linkedin
Answers
Stevan
Stevan
66 Points
28 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