Upload JSON File and Parse
asp.net-mvc, c#, json, twitter-bootstrap
Solution
Just create your form and create your action something like this:
using System.Web.Script.Serialization;
[HttpPost]
public ActionResult Index(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
// get contents to string
string str = (new StreamReader(file.InputStream)).ReadToEnd();
// deserializes string into object
JavaScriptSerializer jss = new JavaScriptSerializer();
var d = jss.Deserialize<dynamic>(str);
// once it's an object, you can use do with it whatever you want
}
}
Problem
I'm using a custom bootstrap, link: http://jasny.github.io/bootstrap/javascript.html#fileupload and I have a button to upload a file. This file is a JSON and I want to read it on my Controller. How can I do this? A method with a File Parameter and read this file using Json Parser.