在我的视图窗口中,我有一个像这样调用 get 事件方法的表单
<form action="GetEvent" method="post">
<input type="submit" value="Click Me" />
</form>
这会在我的 Homecontroller 中调用我的 GetEvent 并像这样处理它
public ActionResult GetEvent()
{
try
{
string at = "aa";
string et = "KI";
string t = "20";
string _checkingUrl = String.Format("http://172.22.22.10/SampleAPI/Event/GetEvents?at={0}&et={1}&t={2}&responseFormat=json", at, et, t);
System.Net.HttpWebRequest request=System.Net.WebRequest.Create(_checkingUrl) as System.Net.HttpWebRequest;
System.Net.HttpWebResponse response=request.GetResponse() as System.Net.HttpWebResponse;
System.IO.StreamReader _readResponse=new System.IO.StreamReader(response.GetResponseStream());
//The encrypted dynamics response in either xml or json
string _responseAsString=_readResponse.ReadToEnd();
JavaScriptSerializer parseResponse = new JavaScriptSerializer();
List<Event> events = parseResponse.Deserialize<List<Event>>
(_responseAsString);
我的事件我在我的模型视图中创建了一个类。它低于这种方法
//return Content(_responseAsString);
_readResponse.Close();
}
catch (Exception e)
{
//log error
}
return View();
}
}
public class Event
{
// side note this variables are the name of the Json Data that i retrieved
public string event_key { get; set; }
public string user_token { get; set; }
public string event_set_key { get; set; }
public string event_type { get; set; }
public string event_date { get; set; }
public string event_amount { get; set; }
public string event_location_key { get; set; }
public string event_location_name { get; set; }
public string event_location_city { get; set; }
public string event_location_state { get; set; }
public string event_location_country { get; set; }
public string event_acknowledged { get; set; }
}
现在的问题是。在我解析 Json 响应并将其放入对象列表中之后。如何在表格中显示它。所以在我单击“单击我”按钮后,它将通过该方法,然后应该出现一个页面,其中包含表中的偶数对象?我有点想通了。我想我可能是 viewbag.eventss = event; 中的事件。然后在 html 中使用它作为 foreach 循环