但未在用户代码中处理

但未在用户代码中处理

本文介绍了system.web.mvc.dll中发生类型'system.nullreferenceexception'的异常,但未在用户代码中处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用devxscheduler mvc和iam调用一个视图,在该视图中我在getschedulersettings()方法的模型方法中有一些html代码,我不知道为什么我在这里得到null引用异常.有人可以澄清一下这是编程新手吗

我尝试过的事情:

Iam using devxscheduler mvc and iam calling a view where i having some html code in model method in getschedulersettings() method and i dont know why iam getting null reference exception here.Can someone please clarify this iam new to programming

What I have tried:

public static SchedulerSettings GetSchedulerSettings()
            {

                return GetSchedulerSettings(null);
            }

        public static SchedulerSettings GetSchedulerSettings(this System.Web.Mvc.HtmlHelper customHtml)
        {
            SchedulerSettings settings = new SchedulerSettings();
            settings.Name = "scheduler";
            settings.CallbackRouteValues = new { Controller = "Home", Action = "SchedulerPartial" };
            settings.EditAppointmentRouteValues = new { Controller = "Home", Action = "EditAppointment" };
            settings.CustomActionRouteValues = new { Controller = "Home", Action = "CustomCallBackAction" };

            settings.Storage.Appointments.Assign(SchedulerDataHelper.DefaultAppointmentStorage);
            settings.Storage.Resources.Assign(SchedulerDataHelper.DefaultResourceStorage);

            settings.Storage.EnableReminders = true;
            settings.GroupType = SchedulerGroupType.None;
            settings.Views.DayView.Styles.ScrollAreaHeight = 400;
            settings.Start = DateTime.Now;
            settings.SetToolbarViewSelectorTemplateContent(container =>
            {
                customHtml.Partial("ViewSelectorPartial");
            });

            return settings;
        }

推荐答案

GetSchedulerSettings(null);


然后您尝试访问该对象的成员,


and you try to access the members of the object,

customHtml.Partial("ViewSelectorPartial");

显然会引发空引用异常 [ ^ ].

将相关参数传递给方法并尝试,它应该可以工作.

签名看起来像是扩展方法 [ ^ ]

which will obviously throw the null reference exception[^].

Pass the relevant parameter to the method and try, it should work.

The Signature looks like an extension method[^]

public static SchedulerSettings GetSchedulerSettings(this System.Web.Mvc.HtmlHelper customHtml)


因此很可能应该从HtmlHelper对象调用方法目录,例如


so most probably you should call the method directory from the HtmlHelper object, like

objHtmlHelper.GetSchedulerSettings();



这篇关于system.web.mvc.dll中发生类型'system.nullreferenceexception'的异常,但未在用户代码中处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:19