ArgumentNullException不能由用户进行管理。 [英] ArgumentNullExceptioncan not be handeled by user.

查看:89
本文介绍了ArgumentNullException不能由用户进行管理。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我从多个表中删除记录时遇到问题,

当我试图删除记录时,它会出现异常

  ArgumentNullExceptioncan     handeled  用户
不能 < span class =code-leadattribute> null 。
参数 名称: 实体





代码:



 [ NonAction] 
private FinancilInstituteWrappergetData( int id)
{
FinancilInstituteWrapper temp = newFinancilInstituteWrapper();
var details = 来自 i indb.IIDBS
join a indb.ACDBS
oni.Idequalsa.Id
join b indb.BIDBSoni.Idequalsb.Id
wherei.Id == id
selectnewFinancilInstituteWrapper
{
II = i,
AC = a,
BI = b
};
foreach (FinancilInstituteWrapper a in 详情)
{
temp。 II = a.II;
temp.BI = a.BI;
temp.AC = a.AC;
}

return temp;
}



 // 
// GET:/ FinancilInstitute / Delete / 5
publicActionResult Delete(int id = 0)
{
return View(getData(id));
}

//
// POST:/ FinancilInstitute / Delete / 5

[HttpPost,ActionName(Delete)]
publicActionResultDeleteConfirmed(int id = 0)
{
FinancilInstituteWrapper wrapper = newFinancilInstituteWrapper();
db.IIDBS.Remove(wrapper.II);
db.ACDBS.Remove(wrapper.AC);
db.BIDBS.Remove(wrapper.BI);
db.SaveChanges();
returnRedirectToAction(Index);
}





查看:

<%@ PageTitle =  语言= C# 的MasterPageFile = 〜/查看/共享/的Site.Master 继承= System.Web.Mvc.ViewPage< BachatGatProjectFinal.Controllers.FinancilInstituteWrapper> 中%GT; 

< h2>删除< / h2>

< h3>您确定要删除此内容吗?< / h3>
< fieldset>
< legend> FinancilInstituteWrapper< / legend>

< div>
<%:Html.HiddenFor(m => m.II.Id)%>
< / div>

< div>
学院名称
<%:Html.DisplayFor(m => m.II.InstituteName)%>
< / div>

< div>
所有者名字
<%:Html.DisplayFor(m => m.II.OwnersFirstName)%>
< / div>

< div>
所有者姓氏
<%:Html.DisplayFor(m => m.II.OwnersLastName)%>
< / div>

< div>
<%:Html.HiddenFor(m => m.AC.Id)%>
< / div>

< div>
地址
<%:Html.DisplayFor(m => m.AC.Address)%>
< / div>

< div>
City
<%:Html.DisplayFor(m => m.AC.City)%>
< / div>

< div>

<%:Html.DisplayFor(m => m.AC.State)%>
< / div>

< div>
PinCode
<%:Html.DisplayFor(m => m.AC.PinCode)%>
< / div>

< div>
电话
<%:Html.DisplayFor(m => m.AC.Phone)%>
< / div>

< div>
电子邮件
<%:Html.DisplayFor(m => m.AC.Email)%>
< / div>

< div>
<%:Html.HiddenFor(m => m.BI.Id)%>
< / div>

< div>
BankName
<%:Html.DisplayFor(m => m.BI.BankName)%>
< / div>

< div>
分支
<%:Html.DisplayFor(m => m.BI.Branch)%>
< / div>

< div>
帐号
<%:Html.DisplayFor(m => m.BI.AccountNumber)%>
< / div>

< div>
MICR
<%:Html.DisplayFor(m => m.BI.MICR)%>
< / div>

< div>
IFSC
<%:Html.DisplayFor(m => m.BI.IFSC)%>
< / div>
< / fieldset>
<%using(Html.BeginForm()){%>
< p>
< inputtype =submitvalue =删除/> |
<%:Html.ActionLink(返回列表,索引)%>
< / p>
<%}%>





请帮助

解决方案

请首先检查完整的进程是否有任何空值进入数据库


由于下面的行可能会抛出您的异常。所以检查该实体的空值(即 indb.BIDBSoni.Idequalsb!= null )在加入之前。



  join  b indb.BIDBSoni.Idequalsb.Id 
其中 i.Id == id


Hi,
I am fetching the problem with deleteing the record from multiple tables,
When I m trying to delete the record its ocours the exception

ArgumentNullExceptioncan not be handeled by user.
Value cannot be null.
Parameter name: entity



Code :

       [NonAction]
private FinancilInstituteWrappergetData(int id)
        {
FinancilInstituteWrapper temp = newFinancilInstituteWrapper();
var details = from i indb.IIDBS
join a indb.ACDBS
oni.Idequalsa.Id
join b indb.BIDBSoni.Idequalsb.Id
wherei.Id==id
selectnewFinancilInstituteWrapper
                          {
                              II = i,
                              AC = a,
                              BI = b
                          };
foreach (FinancilInstituteWrapper a in details)
            {
temp.II = a.II;
                temp.BI = a.BI;
                temp.AC = a.AC;
            }

return temp;
        }


//
// GET: /FinancilInstitute/Delete/5
publicActionResult Delete(int id=0)
        {
return View(getData(id));
        }

//
// POST: /FinancilInstitute/Delete/5

        [HttpPost,ActionName("Delete")]
publicActionResultDeleteConfirmed(int id = 0)
        {
FinancilInstituteWrapper wrapper = newFinancilInstituteWrapper();         
db.IIDBS.Remove(wrapper.II);
db.ACDBS.Remove(wrapper.AC);
db.BIDBS.Remove(wrapper.BI);
db.SaveChanges();
returnRedirectToAction("Index");           
        }



View:

<%@PageTitle=""Language="C#"MasterPageFile="~/Views/Shared/Site.Master"Inherits="System.Web.Mvc.ViewPage<BachatGatProjectFinal.Controllers.FinancilInstituteWrapper>"%>

<h2>Delete</h2>

<h3>Are you sure you want to delete this?</h3>
<fieldset>
<legend>FinancilInstituteWrapper</legend>

<div>
<%:Html.HiddenFor(m=>m.II.Id) %>
</div>

<div>
        Institute Name
<%:Html.DisplayFor(m=>m.II.InstituteName) %>
</div>

<div>
        Owners First Name
<%:Html.DisplayFor(m=>m.II.OwnersFirstName) %>
</div>

<div>
        Owners Last Name
<%:Html.DisplayFor(m=>m.II.OwnersLastName) %>
</div>

<div>
<%:Html.HiddenFor(m=>m.AC.Id) %>
</div>

<div>
        Address
<%:Html.DisplayFor(m=>m.AC.Address) %>
</div>

<div>
        City
<%:Html.DisplayFor(m=>m.AC.City) %>
</div>

<div>
        State
<%:Html.DisplayFor(m=>m.AC.State) %>
</div>

<div>
PinCode
<%:Html.DisplayFor(m=>m.AC.PinCode) %>
</div>

<div>
        Phone
<%:Html.DisplayFor(m=>m.AC.Phone) %>
</div>

<div>
        Email
<%:Html.DisplayFor(m=>m.AC.Email) %>
</div>

<div>
<%:Html.HiddenFor(m=>m.BI.Id) %>
</div>

<div>
BankName
<%:Html.DisplayFor(m=>m.BI.BankName) %>
</div>

<div>
        Branch
<%:Html.DisplayFor(m=>m.BI.Branch) %>
</div>

<div>
        Account Number
<%:Html.DisplayFor(m=>m.BI.AccountNumber) %>
</div>

<div>
        MICR
<%:Html.DisplayFor(m=>m.BI.MICR) %>
</div>

<div>
        IFSC
<%:Html.DisplayFor(m=>m.BI.IFSC) %>
</div>
</fieldset>
<%using (Html.BeginForm()) { %>
<p>
<inputtype="submit"value="Delete"/> |
<%:Html.ActionLink("Back to List", "Index") %>
</p>
<% } %>



Pls help

解决方案

kindly first check the complete process whether is there any null value going into the data base


Your exception may be thrown due to below line.So check the null-ability of that entity (i.e. indb.BIDBSoni.Idequalsb != null ) before do the join.

join b indb.BIDBSoni.Idequalsb.Id
where i.Id==id


这篇关于ArgumentNullException不能由用户进行管理。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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