Hi guys I have the following JSON list
{
"students": [{
"Name" : "Robert Mcguffin",
"Registered" : "2014-07-20 05:34:16",
"Student No:" : 1
} , {
"Name" : "Agathe Dubois",
"Registered" : "2014-05-30 09:46:26",
"Student No:" : 2
} , {
"Name" : "Steven Corral",
"Registered" : "2015-02-11 09:58:16",
"Student No:" : 3
}]
}
I need to be able to publish the following data to a table in an mvc application.
First and foremost I've done my research and it said that I should use deserialization with json.net so it makes an object list with the information supplied. Then I should use a view to publish the list to html.
How do I do this and if I do it will I be able to search the list given above using a dropdown which specifies either Name, Registered or StudentNo and then displays the student that it searched for? I know how to implement the search using sql but not sure if I could search the list otherwise.
Code for my Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StudentApplication.Models
{
public class Students
{
public string Name {get; set;}
public DateTime Registered {get; set;}
public int StudentNo {get; set;}
}
public class StudentList
{
public List<Students> students {get; set;}
}
}
Code for my controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace StudentApplication.Controllers
{
public class UserController : Controller
{
[HttpGet]
public ActionResult List()
{
var resolveRequest = HttpContext.Request;
List<Students> model = new List<Students>();
resolveRequest.InputStream.Seek(0, SeekOrigin.Begin);
string jsonString = new StreamReader(resolveRequest.InputStream).ReadToEnd();
if (jsonString != null)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
model = (List<Students>)serializer.Deserialize(jsonString, typeof(List<Students>);
}
return View();
}
}
}
I got that last bit of code from How to Send Json String to Controller in mvc4 and Deserialize json