Asp.net mvc 视图模型大部分返回为空
我正在为从同事那里继承的ASP.NET MVC应用程序添加附加功能。出于某种原因,除了控制器上的Asp.net mvc 视图模型大部分返回为空,asp.net-mvc,Asp.net Mvc,我正在为从同事那里继承的ASP.NET MVC应用程序添加附加功能。出于某种原因,除了控制器上的AddParticipant方法的视图模型参数中的SelectedPartyRole之外,所有属性都是null,尽管之前从数据库返回了数据 型号: public class AddParticipantViewModel { public string ClaimNumber { get; set; } public string PolicyNumber { get; set; }
AddParticipant
方法的视图模型参数中的SelectedPartyRole
之外,所有属性都是null
,尽管之前从数据库返回了数据
型号:
public class AddParticipantViewModel
{
public string ClaimNumber { get; set; }
public string PolicyNumber { get; set; }
public string PartyNumber { get; set; }
public string PartyName { get; set; }
public string TaxID { get; set; }
public string SelectedPartyRole { get; set; }
public Dictionary<string, string> ValidPartyRoles { get; set; }
}
@model TN_IntegrationDashboard.Web.Models.AddParticipantViewModel
@{
ViewBag.Title = "AddClaimParticipant";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="sectionTitle">
<h2>Add Claim Participant</h2>
</div>
<br /><br /><br />
<fieldset>
<legend></legend>
<div class="status">@ViewBag.Result</div>
<br /><br />
<table style="width: 100%;">
<tr style="background-color:#3B4044;color:white;height:45px; vertical-align: central;font-weight:600;">
<th>Claim Number</th>
<th>Policy Number</th>
<th>Party Number</th>
<th>Party Name</th>
<th>Tax ID</th>
</tr>
<tr>
<td>@Html.DisplayFor(model => model.ClaimNumber)</td>
<td>@Html.DisplayFor(model => model.PolicyNumber)</td>
<td>@Html.DisplayFor(model => model.PartyNumber)</td>
<td>@Html.DisplayFor(model => model.PartyName)</td>
<td>@Html.DisplayFor(model => model.TaxID)</td>
</tr>
</table>
<br /><br /><br />
<div>
<button type="button" id="ShowHide">Select Role</button>
</div>
<br /><br /><br />
<div id="ShowHideUpdateControls" hidden="@(ViewBag.Success = true ? "" : "hidden")">
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table style="width: 100%;">
<tr style="background-color:#3B4044;color:white;height:45px; vertical-align: central;font-weight:600;">
<th>Valid Party Roles</th>
</tr>
<tr>
<td>@Html.DropDownListFor(m => m.SelectedPartyRole,
new SelectList(Model.ValidPartyRoles, "Key", "Value"),
"")</td>
</tr>
</table>
<br /><br /><br />
<input type="submit" value="Save" formaction='@Url.Action("AddParticipant")'>
}
</div>
</fieldset>
public class ClaimController : Controller
{
[HttpGet]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaimParticipant()
{
return View();
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaim(string claimNumber)
{
IClaimManager proxy = CreateClaimManagerProxy();
var claim = proxy.GetClaim(claimNumber);
if (claim == null)
{
ViewBag.Status = "Claim record not found. Please enter a different claim number.";
return View("SearchForClaim");
}
else
{
var modifyClaimViewModel = new ClaimViewModel
{
ClaimNumber = claim.ClaimNumber,
NotificationDate = claim.NotificationDate
};
return View("ModifyClaim", modifyClaimViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaimParticipant(string claimNumber, string partyNumber)
{
IClaimManager claimProxy = CreateClaimManagerProxy();
IPartyAdminManager partyProxy = CreatePartyAdminManagerProxy();
var claim = claimProxy.GetClaim(claimNumber);
var party = partyProxy.GetParty(partyNumber);
var errorMessage = string.Empty;
if (claim == null)
string.Concat(errorMessage, "Claim record not found. Please enter a different claim number. ");
if (party == null)
string.Concat(errorMessage, "Party record not found. Please enter a different party number.");
if (errorMessage.Length > 0)
{
ViewBag.Status = errorMessage;
return View("SearchForClaimParticipant");
}
else
{
Dictionary<string, string> roles = partyProxy.GetPartyRoles();
string partyName = string.Empty;
if (party.BusinessName == null || party.BusinessName == string.Empty)
partyName = string.Concat(party.FirstName, " ", string.Concat(party.MiddleName, " ") ?? string.Empty, party.LastName);
else
partyName = party.BusinessName;
var addParticipantViewModel = new AddParticipantViewModel
{
ClaimNumber = claim.ClaimNumber,
PolicyNumber = claim.PolicyNumber,
PartyNumber = partyNumber,
PartyName = partyName,
TaxID = party.TaxID,
ValidPartyRoles = roles
};
return View("AddClaimParticipant", addParticipantViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult AddParticipant(AddParticipantViewModel viewModel)
{
if (ModelState.IsValid)
{
IClaimManager proxy = CreateClaimManagerProxy();
string result = proxy.AddParticpant(viewModel.ClaimNumber, viewModel.PartyNumber, viewModel.SelectedPartyRole);
ViewBag.Result = result;
}
return View("AddClaimParticipant");
}
private static IIntegrationDashboardManager CreateDashboardManagerProxy()
{
ChannelFactory<IIntegrationDashboardManager> _channelFactory;
_channelFactory = new ChannelFactory<IIntegrationDashboardManager>("*");
IIntegrationDashboardManager channel = _channelFactory.CreateChannel();
return channel;
}
private static IClaimManager CreateClaimManagerProxy()
{
ChannelFactory<IClaimManager> _channelFactory;
_channelFactory = new ChannelFactory<IClaimManager>("*");
IClaimManager channel = _channelFactory.CreateChannel();
return channel;
}
private static IPartyAdminManager CreatePartyAdminManagerProxy()
{
ChannelFactory<IPartyAdminManager> _channelFactory;
_channelFactory = new ChannelFactory<IPartyAdminManager>("*");
IPartyAdminManager channel = _channelFactory.CreateChannel();
return channel;
}
}
公共类AddParticipantViewModel
{
公共字符串ClaimNumber{get;set;}
公共字符串PolicyNumber{get;set;}
公共字符串PartyNumber{get;set;}
公共字符串PartyName{get;set;}
公共字符串TaxID{get;set;}
公共字符串SelectedPartyRole{get;set;}
公共字典ValidPartyRoles{get;set;}
}
查看:
public class AddParticipantViewModel
{
public string ClaimNumber { get; set; }
public string PolicyNumber { get; set; }
public string PartyNumber { get; set; }
public string PartyName { get; set; }
public string TaxID { get; set; }
public string SelectedPartyRole { get; set; }
public Dictionary<string, string> ValidPartyRoles { get; set; }
}
@model TN_IntegrationDashboard.Web.Models.AddParticipantViewModel
@{
ViewBag.Title = "AddClaimParticipant";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="sectionTitle">
<h2>Add Claim Participant</h2>
</div>
<br /><br /><br />
<fieldset>
<legend></legend>
<div class="status">@ViewBag.Result</div>
<br /><br />
<table style="width: 100%;">
<tr style="background-color:#3B4044;color:white;height:45px; vertical-align: central;font-weight:600;">
<th>Claim Number</th>
<th>Policy Number</th>
<th>Party Number</th>
<th>Party Name</th>
<th>Tax ID</th>
</tr>
<tr>
<td>@Html.DisplayFor(model => model.ClaimNumber)</td>
<td>@Html.DisplayFor(model => model.PolicyNumber)</td>
<td>@Html.DisplayFor(model => model.PartyNumber)</td>
<td>@Html.DisplayFor(model => model.PartyName)</td>
<td>@Html.DisplayFor(model => model.TaxID)</td>
</tr>
</table>
<br /><br /><br />
<div>
<button type="button" id="ShowHide">Select Role</button>
</div>
<br /><br /><br />
<div id="ShowHideUpdateControls" hidden="@(ViewBag.Success = true ? "" : "hidden")">
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table style="width: 100%;">
<tr style="background-color:#3B4044;color:white;height:45px; vertical-align: central;font-weight:600;">
<th>Valid Party Roles</th>
</tr>
<tr>
<td>@Html.DropDownListFor(m => m.SelectedPartyRole,
new SelectList(Model.ValidPartyRoles, "Key", "Value"),
"")</td>
</tr>
</table>
<br /><br /><br />
<input type="submit" value="Save" formaction='@Url.Action("AddParticipant")'>
}
</div>
</fieldset>
public class ClaimController : Controller
{
[HttpGet]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaimParticipant()
{
return View();
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaim(string claimNumber)
{
IClaimManager proxy = CreateClaimManagerProxy();
var claim = proxy.GetClaim(claimNumber);
if (claim == null)
{
ViewBag.Status = "Claim record not found. Please enter a different claim number.";
return View("SearchForClaim");
}
else
{
var modifyClaimViewModel = new ClaimViewModel
{
ClaimNumber = claim.ClaimNumber,
NotificationDate = claim.NotificationDate
};
return View("ModifyClaim", modifyClaimViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaimParticipant(string claimNumber, string partyNumber)
{
IClaimManager claimProxy = CreateClaimManagerProxy();
IPartyAdminManager partyProxy = CreatePartyAdminManagerProxy();
var claim = claimProxy.GetClaim(claimNumber);
var party = partyProxy.GetParty(partyNumber);
var errorMessage = string.Empty;
if (claim == null)
string.Concat(errorMessage, "Claim record not found. Please enter a different claim number. ");
if (party == null)
string.Concat(errorMessage, "Party record not found. Please enter a different party number.");
if (errorMessage.Length > 0)
{
ViewBag.Status = errorMessage;
return View("SearchForClaimParticipant");
}
else
{
Dictionary<string, string> roles = partyProxy.GetPartyRoles();
string partyName = string.Empty;
if (party.BusinessName == null || party.BusinessName == string.Empty)
partyName = string.Concat(party.FirstName, " ", string.Concat(party.MiddleName, " ") ?? string.Empty, party.LastName);
else
partyName = party.BusinessName;
var addParticipantViewModel = new AddParticipantViewModel
{
ClaimNumber = claim.ClaimNumber,
PolicyNumber = claim.PolicyNumber,
PartyNumber = partyNumber,
PartyName = partyName,
TaxID = party.TaxID,
ValidPartyRoles = roles
};
return View("AddClaimParticipant", addParticipantViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult AddParticipant(AddParticipantViewModel viewModel)
{
if (ModelState.IsValid)
{
IClaimManager proxy = CreateClaimManagerProxy();
string result = proxy.AddParticpant(viewModel.ClaimNumber, viewModel.PartyNumber, viewModel.SelectedPartyRole);
ViewBag.Result = result;
}
return View("AddClaimParticipant");
}
private static IIntegrationDashboardManager CreateDashboardManagerProxy()
{
ChannelFactory<IIntegrationDashboardManager> _channelFactory;
_channelFactory = new ChannelFactory<IIntegrationDashboardManager>("*");
IIntegrationDashboardManager channel = _channelFactory.CreateChannel();
return channel;
}
private static IClaimManager CreateClaimManagerProxy()
{
ChannelFactory<IClaimManager> _channelFactory;
_channelFactory = new ChannelFactory<IClaimManager>("*");
IClaimManager channel = _channelFactory.CreateChannel();
return channel;
}
private static IPartyAdminManager CreatePartyAdminManagerProxy()
{
ChannelFactory<IPartyAdminManager> _channelFactory;
_channelFactory = new ChannelFactory<IPartyAdminManager>("*");
IPartyAdminManager channel = _channelFactory.CreateChannel();
return channel;
}
}
@model TN\u IntegrationDashboard.Web.Models.AddParticipantViewModel
@{
ViewBag.Title=“addclaicipant”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
添加索赔参与者
@查看包。结果
索赔编号
保单号码
党号
党名
税号
@DisplayFor(model=>model.ClaimNumber)
@DisplayFor(model=>model.PolicyNumber)
@DisplayFor(model=>model.PartyNumber)
@DisplayFor(model=>model.PartyName)
@DisplayFor(model=>model.TaxID)
选择角色
@使用(Html.BeginForm()){
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
有效的参与方角色
@Html.DropDownListFor(m=>m.SelectedPartyRole,
新的选择列表(Model.ValidPartyRoles,“键”、“值”),
"")
}
控制器:
public class AddParticipantViewModel
{
public string ClaimNumber { get; set; }
public string PolicyNumber { get; set; }
public string PartyNumber { get; set; }
public string PartyName { get; set; }
public string TaxID { get; set; }
public string SelectedPartyRole { get; set; }
public Dictionary<string, string> ValidPartyRoles { get; set; }
}
@model TN_IntegrationDashboard.Web.Models.AddParticipantViewModel
@{
ViewBag.Title = "AddClaimParticipant";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="sectionTitle">
<h2>Add Claim Participant</h2>
</div>
<br /><br /><br />
<fieldset>
<legend></legend>
<div class="status">@ViewBag.Result</div>
<br /><br />
<table style="width: 100%;">
<tr style="background-color:#3B4044;color:white;height:45px; vertical-align: central;font-weight:600;">
<th>Claim Number</th>
<th>Policy Number</th>
<th>Party Number</th>
<th>Party Name</th>
<th>Tax ID</th>
</tr>
<tr>
<td>@Html.DisplayFor(model => model.ClaimNumber)</td>
<td>@Html.DisplayFor(model => model.PolicyNumber)</td>
<td>@Html.DisplayFor(model => model.PartyNumber)</td>
<td>@Html.DisplayFor(model => model.PartyName)</td>
<td>@Html.DisplayFor(model => model.TaxID)</td>
</tr>
</table>
<br /><br /><br />
<div>
<button type="button" id="ShowHide">Select Role</button>
</div>
<br /><br /><br />
<div id="ShowHideUpdateControls" hidden="@(ViewBag.Success = true ? "" : "hidden")">
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<table style="width: 100%;">
<tr style="background-color:#3B4044;color:white;height:45px; vertical-align: central;font-weight:600;">
<th>Valid Party Roles</th>
</tr>
<tr>
<td>@Html.DropDownListFor(m => m.SelectedPartyRole,
new SelectList(Model.ValidPartyRoles, "Key", "Value"),
"")</td>
</tr>
</table>
<br /><br /><br />
<input type="submit" value="Save" formaction='@Url.Action("AddParticipant")'>
}
</div>
</fieldset>
public class ClaimController : Controller
{
[HttpGet]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaimParticipant()
{
return View();
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaim(string claimNumber)
{
IClaimManager proxy = CreateClaimManagerProxy();
var claim = proxy.GetClaim(claimNumber);
if (claim == null)
{
ViewBag.Status = "Claim record not found. Please enter a different claim number.";
return View("SearchForClaim");
}
else
{
var modifyClaimViewModel = new ClaimViewModel
{
ClaimNumber = claim.ClaimNumber,
NotificationDate = claim.NotificationDate
};
return View("ModifyClaim", modifyClaimViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult SearchForClaimParticipant(string claimNumber, string partyNumber)
{
IClaimManager claimProxy = CreateClaimManagerProxy();
IPartyAdminManager partyProxy = CreatePartyAdminManagerProxy();
var claim = claimProxy.GetClaim(claimNumber);
var party = partyProxy.GetParty(partyNumber);
var errorMessage = string.Empty;
if (claim == null)
string.Concat(errorMessage, "Claim record not found. Please enter a different claim number. ");
if (party == null)
string.Concat(errorMessage, "Party record not found. Please enter a different party number.");
if (errorMessage.Length > 0)
{
ViewBag.Status = errorMessage;
return View("SearchForClaimParticipant");
}
else
{
Dictionary<string, string> roles = partyProxy.GetPartyRoles();
string partyName = string.Empty;
if (party.BusinessName == null || party.BusinessName == string.Empty)
partyName = string.Concat(party.FirstName, " ", string.Concat(party.MiddleName, " ") ?? string.Empty, party.LastName);
else
partyName = party.BusinessName;
var addParticipantViewModel = new AddParticipantViewModel
{
ClaimNumber = claim.ClaimNumber,
PolicyNumber = claim.PolicyNumber,
PartyNumber = partyNumber,
PartyName = partyName,
TaxID = party.TaxID,
ValidPartyRoles = roles
};
return View("AddClaimParticipant", addParticipantViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey = "", UsersAppSettingKey = "ClaimUpdateAuthorizedUsers")]
public ActionResult AddParticipant(AddParticipantViewModel viewModel)
{
if (ModelState.IsValid)
{
IClaimManager proxy = CreateClaimManagerProxy();
string result = proxy.AddParticpant(viewModel.ClaimNumber, viewModel.PartyNumber, viewModel.SelectedPartyRole);
ViewBag.Result = result;
}
return View("AddClaimParticipant");
}
private static IIntegrationDashboardManager CreateDashboardManagerProxy()
{
ChannelFactory<IIntegrationDashboardManager> _channelFactory;
_channelFactory = new ChannelFactory<IIntegrationDashboardManager>("*");
IIntegrationDashboardManager channel = _channelFactory.CreateChannel();
return channel;
}
private static IClaimManager CreateClaimManagerProxy()
{
ChannelFactory<IClaimManager> _channelFactory;
_channelFactory = new ChannelFactory<IClaimManager>("*");
IClaimManager channel = _channelFactory.CreateChannel();
return channel;
}
private static IPartyAdminManager CreatePartyAdminManagerProxy()
{
ChannelFactory<IPartyAdminManager> _channelFactory;
_channelFactory = new ChannelFactory<IPartyAdminManager>("*");
IPartyAdminManager channel = _channelFactory.CreateChannel();
return channel;
}
}
公共类ClaimController:控制器
{
[HttpGet]
[AuthorizeByConfig(RolesAppSettingKey=“”,UsersAppSettingKey=“ClaimUpdateAuthorizedUsers”)]
公共行动结果搜索Clainficipant()
{
返回视图();
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey=“”,UsersAppSettingKey=“ClaimUpdateAuthorizedUsers”)]
public ActionResult SearchForClaim(字符串claimNumber)
{
IClaimManager proxy=createClaimanagerProxy();
var claim=proxy.GetClaim(claimNumber);
如果(索赔==null)
{
ViewBag.Status=“未找到索赔记录。请输入其他索赔编号。”;
返回视图(“SearchForClaim”);
}
其他的
{
var modifyClaimViewModel=新ClaimViewModel
{
ClaimNumber=claim.ClaimNumber,
NotificationDate=索赔。NotificationDate
};
返回视图(“ModifyClaim”,modifyClaimViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey=“”,UsersAppSettingKey=“ClaimUpdateAuthorizedUsers”)]
public ActionResult SearchForClaimicPant(字符串claimNumber,字符串partyNumber)
{
IClaimManager clainproxy=createclaiminanagerproxy();
IPartyAdminManager partyProxy=CreatePartyAdminManager Proxy();
var索赔=claimProxy.GetClaim(索赔编号);
var party=partyProxy.GetParty(partyNumber);
var errorMessage=string.Empty;
如果(索赔==null)
string.Concat(错误消息,“未找到索赔记录。请输入其他索赔编号”);
如果(参与方==null)
string.Concat(错误消息,“未找到参与方记录。请输入其他参与方编号”);
如果(errorMessage.Length>0)
{
ViewBag.Status=错误消息;
返回视图(“SearchForClaicePant”);
}
其他的
{
字典角色=partyProxy.GetPartyRoles();
string partyName=string.Empty;
if(party.BusinessName==null | | party.BusinessName==string.Empty)
partyName=string.Concat(party.FirstName,“”,string.Concat(party.MiddleName,“”)?string.Empty,party.LastName);
其他的
partyName=party.BusinessName;
var addParticipantViewModel=新的addParticipantViewModel
{
ClaimNumber=claim.ClaimNumber,
保单编号=索赔。保单编号,
PartyNumber=PartyNumber,
PartyName=PartyName,
TaxID=party.TaxID,
ValidPartyRoles=角色
};
返回视图(“AddClaInficiPant”,addParticipantViewModel);
}
}
[HttpPost]
[AuthorizeByConfig(RolesAppSettingKey=“”,UsersAppSettingKey=“ClaimUpdateAuthorizedUsers”)]
公共操作结果AddParticipant(AddParticipantViewModel viewModel)
{
if(ModelState.IsValid)
{
IClaimManager proxy=createClaimanagerProxy();
字符串结果=proxy.AddParticpant(viewModel.ClaimNumber、viewModel.PartyNumber、viewModel.SelectedPartyRole);
ViewBag.Result=结果;
}
返回视图(“addclaicipant”);
}
专用静态IIintegrationDashboardManager CreateDashboardManagerProxy()
{
渠道工厂(ChannelFactory);;
_channelFactory=新的channelFactory(“*”);
IIintegrationDashboardManager通道=_channelFactory.CreateChannel();
返回通道;
}
专用静态IClaimManager CreateClaimanagerProxy()
{
渠道工厂(ChannelFactory);;
_channelFactory=新的channelFactory(“*”);
IClaimManager通道=_channelFactory.CreateChannel();
返回通道;
}
专用静态IPartyAdminManager CreatePartyAdminManagerProxy()
{
渠道工厂(ChannelFactory);;
_channelFactory=新的channelFactory(“*”);
IPartyAdminManager通道=_channelFactory.CreateChannel();
返回通道;
}
}