我有一些奇怪的功能,并且想知道是否还有其他人遇到过这个问题。
我有一个视图模型,它通过存储过程和vb对象从数据库中收集数据(不,我不知道vb这是遗留的)
当我执行程序时,通过控制器按预期收集数据。当我调试它时,我可以看到所有参数都填充了信息。但是,当涉及到视图时,它表示参数为null。我已经包含了我的代码
型号:
public class PersonIncomeViewModel
{
public string IncomeTypeDesc { get; set; }
public string IncomeDesc { get; set; }
public string Income { get; set; }
}
public class PersonIncomeListViewModel
{
public int? PersonId { get; set; }
public List<PersonIncomeListItem> Incomes { get; set; }
public PersonIncomeListViewModel()
{
Incomes = new List<PersonIncomeListItem>();
}
}
public class PersonLookupViewModel : Queue.QueueViewModel
{
public int Action { get; set; }
public bool ShowAdvancedFilters { get; set; }
//Person Search Variables
[Display(Name = @"Search")]
public string SpecialSearch { get; set; }
[Display(Name = @"Person Id")]
public int? PersonId { get; set; }
[Display(Name = @"Full Name")]
public string FullName { get; set; }
[Display(Name = @"SSN")]
public string SSN { get; set; }
public string AddressStatus { get; set; }
public string EmploymentStatus { get; set; }
public PersonIncomeViewModel Income { get; set; }
public List<PersonIncomeListItem> Incomes { get; set; }
public PersonLookupViewModel()
{
Income = new PersonIncomeViewModel();
Incomes = new List<PersonIncomeListItem>();
}
}
控制器:
public ActionResult _Income(int id)
{
var vm = new PersonLookupViewModel();
var personManager = new dtPerson_v10_r1.Manager( ref mobjSecurity);
//var person = personManager.GetPersonObject((int)id, vIncludeIncomes: true);
var person = personManager.GetPersonObject(id, vIncludeIncomes: true);
var look = JsonConvert.SerializeObject(person.Incomes);
foreach (dtPerson_v10_r1.Income income in person.Incomes)
{
if (income.IncomeType_ID == 0)
{
var item = new PersonIncomeListItem
{
IncomeTypeDesc = "Unknown",
IncomeDesc = income.IncomeDesc,
Income = mobjFormat.FormatObjectToCurrencyString(income.Income)
};
vm.Incomes.Add(item);
}
if (income.IncomeType_ID == 1)
{
var item = new PersonIncomeListItem
{
IncomeTypeDesc = "Alimony",
IncomeDesc = income.IncomeDesc,
Income = mobjFormat.FormatObjectToCurrencyString(income.Income)
};
vm.Incomes.Add(item);
}
if (income.IncomeType_ID == 2)
{
var item = new PersonIncomeListItem
{
IncomeTypeDesc = "Child Support",
IncomeDesc = income.IncomeDesc,
Income = mobjFormat.FormatObjectToCurrencyString(income.Income)
};
vm.Incomes.Add(item);
}
}
return PartialView(vm);
}
查看:
@using dtDataTools_v10_r1
@using ds_iDMS.Models.Person
@model ds_iDMS.Models.Person.PersonLookupViewModel
@{
var format = new dtDataTools_v10_r1.CustomFormat();
var newInitials = (Model.Income.IncomeTypeDesc.First().ToString() + Model.Income.IncomeDesc.First().ToString() + Model.Income.Income.First().ToString()).ToUpper();
}
using (Html.DSResponsiveRow(numberOfInputs: ExtensionMethods.NumberOfInputs.TwoInputs))
{
using (Html.DSCard(ExtensionMethods.Icon.CustomText, iconInitials: newInitials, color: ExtensionMethods.Colors.PrimaryBlue))
{
<div>@Model.Income.IncomeTypeDesc</div>
<div>@Model.Income.IncomeDesc</div>
<div>@Model.Income.Income</div>
}
}
我们已经构建了一些扩展,但它们与问题无关
出错的行是这一行:
var newInitials =(Model.Income.IncomeTypeDesc.First()。ToString()+ Model.Income.IncomeDesc.First()。ToString()+ Model.Income.Income.First()。ToString())。 ToUpper的();
这会驱动视图上的所有扩展方法,当我在其上运行调试器时,所有参数都读为null,但就像我说的那样,当我运行调试器并在控制器中检查它们时,它们是正确填充的。
对于长篇文章感到抱歉,但我想确保所有细节都在那里
答案 0 :(得分:0)
这是将Object model
传递给Partial View
return PartialView("YourViewName", vm);
或使用Views
路径
return PartialView("~/YourView.cshtml", vm);
修改强>
尝试像这样开始你的行动方法
var vm= new Person();
vm.PersonLookupViewModel = new PersonLookupViewModel();
答案 1 :(得分:0)
问题解决了我的一些vb对象出了问题,让vb的人看看它们并修复了它们。
感谢您的所有帮助
<强> 修改 强> 必须要发生的是vb对象必须重写,我的逻辑就像开始时一样好。我标记了对我的问题的一个回答作为答案,因为如果没有附加vb对象的真实MVC,那将完美地运作