0

I have a string in my model.The string is actually XML content. I have a link on my page, when clicked it opens a new tab and displays the text as XML.

The result should be the same as when I right click on an xml file and open with Internet Explorer. The difference is that this is no file, its text that I need to display as XML in a new tab.

Anyone have an idea how to achieve this without creating a file and without giving a path to a file.

1 Answer 1

1

You could have a controller that will serve this XML and set the proper content type header:

public class MyXMLController: Controller
{
    public ActionResult Index()
    {
        MyModel model = GetModelFromSomewhere(...);
        return Content(model.StringPropertyContainingXML, "text/xml");
    }
}

now all that's left is to write an anchor link pointing to /myxml/index:

@Html.ActionLink("Click to open XML", "index", "myxml", null, new { _target = "blank" })
Sign up to request clarification or add additional context in comments.

1 Comment

Its actualy on grid cell click and im passing the event.args.value as the data through ajax call to the controller....will this still work

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.