Web API - Rendering Razor view by default?

后端 未结 5 968
执念已碎
执念已碎 2021-02-13 16:52

How do I get Web API to render a Razor view using the model that it returns? And only XML/JSON when the accept headers (or .extension) is set? Is this even possible?

It

5条回答
  •  旧时难觅i
    2021-02-13 17:52

    It seems crazy to require one set of controllers for rendering HTML and another for JSON/XML if they're working on the same models.

    AFAIK, that's how it is. Standard controllers should be used for rendering HTML and ApiControllers for JSON/XML.

提交回复
热议问题