提问人:musfirah hamid 提问时间:10/9/2023 更新时间:10/9/2023 访问量:19
将数据从页面保存到 XML 文件时出错
error while saving data from page to xml file
问:
我有 2 个帐户,一个是已确认的,另一个是未确认的。用户点击reportComparison按钮,它显示两个账户的数据。如果用户认为数据是错误的,他可以从可用的下拉列表中更改它,下拉列表也在同一页面上。然后他可以在给定的文本区域中添加注释。有一个局 ID 是自动选择的。不,问题是当用户单击报告按钮将帐户数据保存在XML文件中时,它会抛出对象引用错误,尽管我添加了条件检查,如果分析的值为null,则将其替换为0。
这是我的代码,
[HttpPost]
public ActionResult SaveReport(int BureauID, string Note, int? Incorrect_CustomerAccountId, int? Incorrect_C_CustomerAccountId, int? Correct_CustomerAccountId, int? Correct_C_CustomerAccountId)
{
try
{
var report = new Report
{
BureauID = BureauID,
Note = Note,
};
report.InCorrectMapping.CustomerAccount = Incorrect_CustomerAccountId.HasValue
? new VM_CustomerAccount().FindDetailsById(Incorrect_CustomerAccountId.Value)
: null;
report.InCorrectMapping.CCustomerAccount = Incorrect_C_CustomerAccountId.HasValue
? new VM_CustomerAccount().FindDetailsById(Incorrect_C_CustomerAccountId.Value)
: null;
report.CorrectMapping.CustomerAccount = Correct_CustomerAccountId.HasValue
? new VM_CustomerAccount().FindDetailsById(Correct_CustomerAccountId.Value)
: null;
report.CorrectMapping.CCustomerAccount = Correct_C_CustomerAccountId.HasValue
? new VM_CustomerAccount().FindDetailsById(Correct_C_CustomerAccountId.Value)
: null;
var serializer = new XmlSerializer(typeof(Report));
using (var writer = new StreamWriter(Server.MapPath("~/XML/Report.xml")))
{
serializer.Serialize(writer, report);
}
return Content("XML data saved successfully!", "text/plain");
}
catch (Exception ex)
{
return Content("Error: " + ex.Message, "text/plain");
}
}
答: 暂无答案
评论