Search code examples
asp.net-mvc-5viewdatawebapi2

ViewData is not working on Razor View on MVC Web API 2


Please help I am trying to create an Error View on MVC Web API and using custom filter and I am throwing all errors on controller's view and passing the data on ViewData and writing it on Razor View.

My Controller (not ApiController) inside the solution project of MVC WebAPI has being pass a ViewData to the Razor View that is under the MVC Web API project was not working. Please Help!

I am using MVC 5 Web API.


Solution

  • Use @ instead of <%=%>

    For Ex.

    To display time in ViewData

    @ViewData["CurrentTime"]