.NET MVC – Illegal characters in path

Scenario
Render a ASP.NET MVC Razor view with a model from the controller.

Error / Exception
System.ArgumentException: Illegal characters in path.

Cause
The model from the controller was returning JSON and the view had declared “@model string” to handle the JSON.

Solution
Updates in both controller and view. Change controller return type from string to the object.

Controller
Original: return View(JsonConvert.SerializeObject(List));
Change to: return View(List);

View
Original: @model string
Change to: @model List<object>

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.