“'modToSend'这个名字在当前上下文中不存在”

本文关键字:上下文 不存在 modToSend | 更新日期: 2023-09-27 18:33:44

我的Homecontroller中有这段简单的代码.cs,但我在最后一行收到错误消息,说"名称'modToSend'在当前上下文中不存在"。这怎么可能?只有在最后一行才不知道????

public class HomeController : Controller, IDisposable
{
    private MvcEShop2.WcfEshop2Service.Eshop2ServiceClient proxy = null;
    private String GetDuration(DateTime startdatum, DateTime einddatum)
    {
        String maand1 = startdatum.Month.ToString("MMMM");
        String maand2 = einddatum.Month.ToString("MMMM");
        String duration = "";
        if (maand1 == maand2)
        {
            duration = startdatum.Day.ToString()
                + " - " + einddatum.Day.ToString()
                + " " + maand1
                + " " + startdatum.Year.ToString();
        }
        else
        {
            duration = startdatum.Day.ToString()
                + startdatum.Month.ToString("MMMM")
                + " - " + einddatum.Day.ToString()
                + " " + einddatum.Month.ToString("MMMM")
                + " " + startdatum.Year.ToString();
        }
        return duration;
    }

    public HomeController()
     {
         proxy = new MvcEShop2.WcfEshop2Service.Eshop2ServiceClient();
     }
    struct EventStruct
    {
        public SEvent Event { get; set; }
        public String Duration { get; set; }
    };
    public ActionResult Index()
    {
        List<SEvent> modFromWcf = proxy.GetAllEventsByPeriod(@System.DateTime.Now.Year, @System.DateTime.Now.Year + 1, "EN").ToList();
        List<EventStruct> modTosend = new List<EventStruct>();
        foreach (SEvent item in modFromWcf)
        {
            EventStruct ES;
            ES.Event = item;
            ES.Duration = GetDuration(item.StartDate ,item.EndDate);
            modTosend.Add(ES);
        };
        return View("Index", modToSend);
    }
}

“'modToSend'这个名字在当前上下文中不存在”

如果这是从代码中直接复制和粘贴,请检查参数中"S"的大小写到返回的视图。