0

Im using aspx engine. I've been trying to push data into my list but i don't know how. every time i run the program it says create new instance of an object..im not too sure what they talking about..but i did create an instance of the class but still didnt work Can anyone please help me

this is my trying to populate data in my homecontroller

    public ActionResult GetEvent()
    {
        try
        {

            string i = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa";
            string et = "KI2XfwQNByLPFdK4i3a74slLT7sjjzYRi9RR7zEtCoQ%3D";
            string t = "20111128183020";
            string _checkingUrl =  String.Format("http://172.22.22.10/SampleAPI/Event/GetEvents?at={0}&et={1}&t={2}&responseFormat=json", i, 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
            var _responseAsString=_readResponse.ReadToEnd();
            JavaScriptSerializer parseResponse = new JavaScriptSerializer();

            List<Event> events = parseResponse.Deserialize<List<Event>>(_responseAsString);

            Event eventOjb = new Event();
            events.Add(eventOjb);

            ViewBag.eventss = events;

            _readResponse.Close();
            // check json object
            return Content(_responseAsString.ToString());  



        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
            //log error
        }
        return View();
    }

this is my Event class that is in the model folder

  using System;
  using System.Collections.Generic;
 using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;


 namespace StopMalaria.Models
 {
public class Event
{
    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; }
}

}

this is my html trying to step through the list and create a table and error message comes on the foreach loop that says Object reference not set to an instance of an object

 <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    GetEvent
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">


   <table id="eventist" border="0" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th>
                event_key
            </th>
             <th>
                user_token
            </th>                
            <th>
                event_set_key
            </th>           
            <th>
                event_type
            </th>
             <th>
              event_date
            </th>
              <th>
                event_amount
            </th>
             <th>
                event_location_key
            </th>                
            <th>
                event_location_name
            </th>           
            <th>
                event_location_city
            </th>
             <th>
              event_location_state
            </th>
            <th>
                event_location_country
            </th>
             <th>
              event_acknowledged
            </th>
        </tr>
    </thead>
    <tbody>
    <%List<StopMalaria.Models.Event> events = new List<StopMalaria.Models.Event>();%>
    <%events = ViewBag.eventss;%>

    <% foreach (var item in events )
       { %>

        <tr>
            <td>
                <%: item.event_key%>
            </td>
            <td>
                  <%: item.user_token%>
            </td>               
            <td>
                <%: item.event_set_key%>
            </td>           
            <td>
                <%: item.event_type%>
            </td> 
             <td>
                <%: item.event_date%>
            </td>
            <td>
                  <%: item.event_amount%>
            </td>               
            <td>
                <%: item.event_location_key%>
            </td>           
            <td>
                <%: item.event_location_name%>
            </td> 
             <td>
                <%: item.event_location_city%>
            </td>
            <td>
                  <%: item.event_location_state%>
            </td>               
            <td>
                <%: item.event_location_country%>
            </td>           
            <td>
                <%: item.event_acknowledged%>
            </td>                   
        </tr>

    <% } %>
    </tbody>
    </table>






</asp:Content>

Dynamically scale images to fit a specified size width and height

So after extensive research and tons of jQuery and Javascript solutions I simply could not find a way in which to dynamically scale images to a specified size both horizontally and vertically, I found tons of information on scaling to fit width wise and keep the aspect ratio, or scaling to fit height wise and keep the aspect ratio, but couldn't figure out whether the image was too tall or too short and adjust accordingly.

So in my example, I had a <div> with a set width of 460px and a set height of 280px, and i need the image to fit, all of itself into that area without stretching (maintaining its aspect ratio)

4

1 に答える 1

0

例外がスローされている正確な場所はどこですか?

何から返されているか

 _readResponse.ReadToEnd();

レスポンスをデシリアライズしようとすると、どのeventsようになりますか?

最後に、これが問題の原因ではないと確信していますか:

        Event eventOjb = new Event();
        events.Add(eventOjb);

文字列プロパティは設定されず、null ポインター例外が発生します。

于 2012-06-18T20:49:02.120 に答える