用户未处理参数null异常 [英] argument null exception was unhandled by user

查看:132
本文介绍了用户未处理参数null异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

控制器代码



public ActionResult GatePass()//用于填充GatePass视图上的值

{

Guid aId = new Guid();

AppointmentModel objAppointmentModel = new AppointmentModel();

objAppointmentModel = this._iAppointmentService.GetAppointmentByAckId(aId);

返回查看(objAppointmentModel);





}





[HttpPost] //用于根据给定确认填充GatePass View上的值。

public ActionResult GatePass(AppointmentModel appointmentModel)

{







List< validationresult> ValidationResultlist = this._iAppointmentService.GatePassValidation(appointmentModel);

if(ValidationResultlist!= null&& ValidationResultlist.Count()> 0)

{

// VisitorModel objvisitorModel = this._iAppointmentService.InitiateVisitor();

// appointmentModel.SecurityQuestionList = objvisitorModel.SecurityQuestionList;



ControllerExtensions.AddModelErrors(this,ValidationResultlist);

//返回View(GatePass,appointmentModel);

返回View(appointmentModel);

}

其他

{

AppointmentModel objAppointmentModel = new AppointmentModel();

if(appointmentModel。 AcknowledgementID!= Guid.Empty)

{

objAppointmentModel = this ._iAppointmentService.GetAppointmentByAckId(appointmentModel.AcknowledgementID);



}

返回查看(objAppointmentModel);

}



}

验证方法





public List< validationresult> GatePassValidation(Models.AppointmentModel appointmentModel)

{

List< validationresult> gatePassvalidationResultlist = new List< validationresult>();

try

{

if(appointmentModel == null)

{

ValidationResult vr = new ValidationResult();

vr.MemberName =GlobleError;

vr.Message =约会记录不是找到;

gatePassvalidationResultlist.Add(vr);

}



if(string.IsNullOrEmpty(appointmentModel) .AcknowledgementID.ToString()))

{

ValidationResult vr = new ValidationResult();

vr.MemberName =AcknowledgementID;

vr.Message =请输入ID;

gatePassvalidationResultlist.Add(vr);

}

}

catch(exception ex)

{

ValidationResult vr = new ValidationResult();

vr.MemberName =GlobleError;

vr.Message =错误:+ ex.Message;

gatePassvalidationResultlist.Add(vr);



}

返回gatePassvalidationResultlist;

}





.cshtml



@ Html.LabelFor(model => model.VisitorName,new {htmlAttributes = new {@class =form-control input-sm}})我在此行参数中收到错误null异常未被用户代码

Controller code

public ActionResult GatePass( )//for Populate the values on GatePass View
{
Guid aId = new Guid();
AppointmentModel objAppointmentModel = new AppointmentModel();
objAppointmentModel = this._iAppointmentService.GetAppointmentByAckId(aId);
return View(objAppointmentModel);


}


[HttpPost]//For Populate the values on GatePass View based on Given acknowledgementId
public ActionResult GatePass(AppointmentModel appointmentModel)
{



List<validationresult> ValidationResultlist = this._iAppointmentService.GatePassValidation(appointmentModel);
if (ValidationResultlist != null && ValidationResultlist.Count() > 0)
{
// VisitorModel objvisitorModel = this._iAppointmentService.InitiateVisitor();
// appointmentModel.SecurityQuestionList = objvisitorModel.SecurityQuestionList;

ControllerExtensions.AddModelErrors(this, ValidationResultlist);
//return View("GatePass", appointmentModel);
return View(appointmentModel);
}
else
{
AppointmentModel objAppointmentModel = new AppointmentModel();
if (appointmentModel.AcknowledgementID != Guid.Empty)
{
objAppointmentModel = this._iAppointmentService.GetAppointmentByAckId(appointmentModel.AcknowledgementID);

}
return View(objAppointmentModel);
}

}
Validation method


public List<validationresult> GatePassValidation(Models.AppointmentModel appointmentModel)
{
List<validationresult> gatePassvalidationResultlist = new List<validationresult>();
try
{
if (appointmentModel == null)
{
ValidationResult vr = new ValidationResult();
vr.MemberName = "GlobleError";
vr.Message = "Appointment Record not found";
gatePassvalidationResultlist.Add(vr);
}

if (string.IsNullOrEmpty(appointmentModel.AcknowledgementID.ToString() ))
{
ValidationResult vr = new ValidationResult();
vr.MemberName = "AcknowledgementID";
vr.Message = "Please enter ID";
gatePassvalidationResultlist.Add(vr);
}
}
catch (Exception ex)
{
ValidationResult vr = new ValidationResult();
vr.MemberName = "GlobleError";
vr.Message = "Error : " + ex.Message;
gatePassvalidationResultlist.Add(vr);

}
return gatePassvalidationResultlist;
}


.cshtml

@Html.LabelFor(model => model.VisitorName, new { htmlAttributes = new { @class = "form-control input-sm " } })I am getting error in this line argument null exception was unhandled by user code"

推荐答案

不是一个非常明确的问题,但也许这些提示可以帮助你:

Not a very clear question but maybe these tips can help you:



  1. 使用使用调试器检查值的断点。您还可以使用断点视图。
  2. 其他代码使用 appointmentModel 而不是 model 。也许是一个错字?

  1. Use a breakpoint to check the values using the debugger. You can also use breakpoints is views.
  2. Other code uses appointmentModel instead of model. Maybe a typo?

祝你好运!


这篇关于用户未处理参数null异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆