I have a json file that I would like to include as content to my MVC 4 Web Application. I add the file to my Content folder and mark 'Build Action' as 'Content' and 'Copy to Output Directory' as 'Do not copy'. Now if I browse to http://[my site]/content/myjsonfile.json I get an HTTP 404. I mess around with all of the build actions and copy to output selections and still doesn't work. I change the json file extension to txt and then it works. Is this a bug? My site is published using Windows Azure. Thanks for any feedback.
In Solution Explorer, right-click the Controllers folder and then click Add, then Controller. In the Add Scaffold dialog box, click MVC 5 Controller with views, using Entity Framework, and then click Add. Select Movie (MvcMovie. Models) for the Model class.
The @model directive allows access to the list of movies that the controller passed to the view by using a Model object that's strongly typed. For example, in the Index.cshtml view, the code loops through the movies with a foreach statement over the strongly typed Model object: CSHTML Copy.
Luckily, the answer is yes. Combining ASP.NET Webforms and ASP.NET MVC in one application is possible—in fact, it is quite easy. The reason for this is that the ASP.NET MVC framework has been built on top of ASP.NET. There's actually only one crucial difference: ASP.NET lives in System.
The problem is that your webserver doesn't recognize the filetype. Add this line to your web.config:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json; charset=UTF-8" />
</staticContent>
</system.webServer>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With