我发现我的索引页面没有显示当前登录用户的更新用户信息。因此,我从
更改了表单页面:<div class="col-xs-4">
<div class="col-md-4">
@Html.HiddenFor(model => model.SubmittedDate, new { Value = System.DateTime.Now })
@Html.HiddenFor(model => model.SubmittedBy, new { Value = Model.ADAccount })
</div>
</div>
**to:**
<div class="col-xs-4">
<div class="col-md-4">
@Html.HiddenFor(model => model.SubmittedDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.HiddenFor(model => model.SubmittedBy, new { htmlAttributes = new { @class = "form-control" } })
@Html.HiddenFor(model => model.UpdatedDate, new { Value = System.DateTime.Now })
@Html.HiddenFor(model => model.UpdateBy, new { htmlAttributes = new { Value = Model.ADAccount } })
</div>
</div>
我也曾尝试过这样更改表单页面,但它没有做任何更改:
@Html.HiddenFor(model => model.UpdateBy, new { Value = Model.ADAccount })
表单页面中的提交看起来像这样:
@(Html.Kendo().Button()
.Name("submit")
.Content("Submit")
.HtmlAttributes(new { @class = "k-primary" })
.Events(ev => ev.Click("onClick")))
但是由于某种原因,它仍然没有在索引列表中显示UpdateBy。我在Controller中没有看到针对UpdateBy或SubmittedBy的特定参考。我在ApplicantCapturedData.cs列表中都看到了它们:
public string UpdateBy { get; set; }
public string SubmittedBy { get; set; }
我在ApplicantController.cs中看到,“编辑帖子”在数据库中放置了一些数据,但没有特别提到updateBy或SubmittedBy变量或模型。但是,在旧代码中,SubmittedBy变量更改的确显示在索引列表中。我查看了该项目,除了ApplicantController
之外,没有对SubmittedBy的特定引用。当我将手表放在UpdateBy上时,我看到它在旧用户,我和null之间来回移动。显然,它以旧用户结尾,因为提交表单后,这就是索引上的申请人列表中显示的内容。
关于如何解决此问题的任何想法?我是MVC的新手,我不确定为什么这种更改没有回到模型/数据库中。当applicantController获取applicantCapturedData时,它将显示UpdateBy的旧值,而不是新值。
“编辑方法”应将当前登录的用户而不是BD数据返回到视图,但不是。我不确定为什么。
我看着controller not receiving model info,但对我来说似乎不是同一问题。
让我知道您是否认为我遗漏了您需要的任何重要信息。为了清晰明了起见,我显然不能在此处发布所有mvc文件和代码。
******更新********* 这是ApplicantController.cs中的Edit / Post方法。它并没有专门引用SubmittedBy或UpdateBy,但是即使我们以当前AD用户的形式更新了SubmittedBy部分,该索引也确实显示在索引中:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ApplicantCapturedData applicantCapturedData)
{
var eRecordSchedulinglist = applicantCapturedData.ERecordScheduling;
var eRecordScheduling = new ERecordScheduling();
// int IDs = applicantCapturedData.ID;
//updating Provider License
var providerLicenselist = applicantCapturedData.ProviderLicense;
var providerLicense = new ProviderLicense();
var eprescribelist = applicantCapturedData.EPrescribe;
var eprescribe = new EPrescribe();
//updating payor table
var payorlist = applicantCapturedData.Payor;
var payor = new Payor();
//updating tax table
var taxlist = applicantCapturedData.TaxNPITaxonomy;
var tax = new TaxNPITaxonomy();
if (ModelState.IsValid)
{
//ERecordScheduling eRecordScheduling = new ERecordScheduling();
db.Entry(applicantCapturedData).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
int getid = applicantCapturedData.ID;
//Getting values for provider license already in db
var query = from p in db.ProviderLicenses
where p.ApplicantCapturedData_ID == getid
select p;
//deleting the existing rows
foreach (var i in query)
{
db.ProviderLicenses.Remove(i);
}
db.SaveChanges();
int c = 1;
if (providerLicenselist != null)
{
var updatePLS = providerLicenselist.ToList();
// adding only new record to db
foreach (var i in updatePLS)
{
providerLicense.LicenseNumber = i.LicenseNumber;
providerLicense.State = i.State;
providerLicense.ProviderLicenseID = i.ProviderLicenseID;
i.ApplicantCapturedData_ID = getid;
if (providerLicense.ProviderLicenseID <= c)
{
providerLicense.ProviderLicenseID = providerLicense.ProviderLicenseID++;
}
db.ProviderLicenses.Add(i);
db.SaveChanges();
}
}
//getting Values already existing in db for Erecording Schedulign
var queryERS = from p in db.ERecordSchedulings
where p.ApplicantCapturedData_ID == getid
select p;
//deleting the existing rows
foreach (var i in queryERS)
{
db.ERecordSchedulings.Remove(i);
}
db.SaveChanges();
if (eRecordSchedulinglist != null)
{
var updateESCH = eRecordSchedulinglist.ToList();
foreach (var item in updateESCH)
{
eRecordScheduling.DepartmentName = item.DepartmentName;
eRecordScheduling.Shedules = item.Shedules;
eRecordScheduling.VisitType = item.VisitType;
eRecordScheduling.GenericProvider = item.GenericProvider;
eRecordScheduling.ERecordSchedulingID = item.ERecordSchedulingID;
// a.ApplicantCapturedData_ID = newid;
item.ApplicantCapturedData_ID = getid;
if (eRecordScheduling.ERecordSchedulingID <= c)
{
eRecordScheduling.ERecordSchedulingID = eRecordScheduling.ERecordSchedulingID++;
}
//save to db
db.ERecordSchedulings.Add(item);
db.SaveChanges();
}
}
//Getting Values that already exisit in db for Taxonomy
var querytaxo = from p in db.TaxNPITaxonomies
where p.ApplicantCapturedData_ID == getid
select p;
//deleting the existing rows
foreach (var i in querytaxo)
{
db.TaxNPITaxonomies.Remove(i);
}
db.SaveChanges();
if (taxlist != null)
{
var UpdateTaxo = taxlist.ToList();
foreach (var t in UpdateTaxo)
{
tax.GroupNPI = t.GroupNPI;
tax.Notes = t.Notes;
tax.TaxID = t.TaxID;
tax.TaxNPITaxonomyID = t.TaxNPITaxonomyID;
tax.Taxonomy = t.TaxID;
t.ApplicantCapturedData_ID = getid;
if (tax.TaxNPITaxonomyID <= c)
{
tax.TaxNPITaxonomyID = tax.TaxNPITaxonomyID++;
}
db.TaxNPITaxonomies.Add(t);
db.SaveChanges();
}
}
var queryeprescribe = from p in db.EPrescribes
where p.ApplicantCapturedData_ID == getid
select p;
foreach (var i in queryeprescribe)
{
db.EPrescribes.Remove(i);
}
db.SaveChanges();
if (eprescribelist != null)
{
var updateeprescribe = eprescribelist.ToList();
foreach (var t in updateeprescribe)
{
eprescribe.EPrescribeOptions = t.EPrescribeOptions;
eprescribe.ID = t.ID;
t.ApplicantCapturedData_ID = getid;
if (eprescribe.ApplicantCapturedData_ID <= c)
{
eprescribe.ApplicantCapturedData_ID = eprescribe.ApplicantCapturedData_ID++;
}
db.EPrescribes.Add(t);
db.SaveChanges();
}
}
//Geting values that already exist in db for Payors
var queryPayor = from p in db.Payors
where p.ApplicantCapturedData_ID == getid
select p;
//deleting the existing rows
foreach (var i in queryPayor)
{
db.Payors.Remove(i);
}
db.SaveChanges();
if (payorlist != null)
{
var updatepayor = payorlist.ToList();
foreach (var p in updatepayor)
{
payor.Pyor = p.Pyor;
payor.PayorID = p.PayorID;
p.ApplicantCapturedData_ID = getid;
if (payor.PayorID <= c)
{
payor.PayorID = payor.PayorID++;
}
db.Payors.Add(p);
db.SaveChanges();
}
}
return RedirectToAction("Index");
}
return View(applicantCapturedData);
}
这是ApplicantController.cs中的保存内容。它也没有对UpdateBy或SubmittedBy的特定引用,但是当我更改AD用户时,SubmittedBy用于更新:
// [HttpPost]
public ActionResult Save(ApplicantCapturedData applicantCapturedData)
{
ViewBag.PostedBills = applicantCapturedData.BillingAreas;
applicantCapturedData.BillingAreas = applicantCapturedData.BillingAreas;
//updating eRecordScheduling
var list = applicantCapturedData.ERecordScheduling;
var a = new ERecordScheduling();
var OtherAddressList = applicantCapturedData.PracticeInfoOtherLocations;
var otheraddresses = new PracticeInfoOtherLocation();
//var payorlist = applicantCapturedData.Payor;
//var payor = new Payor();
// int IDs = applicantCapturedData.ID;
//updating Provider License
var providerLicenselist = applicantCapturedData.ProviderLicense;
var providerLicense = new ProviderLicense();
var Eprescribelist = applicantCapturedData.EPrescribe;
var eprescribe = new EPrescribe();
//updating payor table
var payorlist = applicantCapturedData.Payor;
var payor = new Payor();
//updating tax table
var taxlist = applicantCapturedData.TaxNPITaxonomy;
var tax = new TaxNPITaxonomy();
// var lastEnt = db.ERecordSchedulings.AsEnumerable().Where(i => i.ERecordSchedulingID.CompareTo(a.ERecordSchedulingID))
int c = 1;//lastEnter.LastOrDefault().ERecordSchedulingID;
if (ModelState.IsValid)
{
db.ApplicantCapturedDatas.Add(applicantCapturedData);
// db.ERecordSchedulings.Add(applicantCapturedData);
db.SaveChanges();
//db.ERecordSchedulings.Add(applicantCapturedData.ERecordScheduling);
//get the primary key id after adding to the Db
int newid = applicantCapturedData.ID;
if (applicantCapturedData.ERecordScheduling != null)
{
// check if we have more record on Erecord scheduling using the count
//if count is greater than zero we have record to add to db.
if (applicantCapturedData.ERecordScheduling.Count() > 0)
{
/*
* This loops thru the list and add record
*
*/
foreach (var item in list)
{
a.DepartmentName = item.DepartmentName;
a.Shedules = item.Shedules;
a.VisitType = item.VisitType;
a.GenericProvider = item.GenericProvider;
a.ERecordSchedulingID = item.ERecordSchedulingID;
// a.ApplicantCapturedData_ID = newid;
item.ApplicantCapturedData_ID = newid;
//if you put a breakpoint at the beginning of this class you will see that all id is 0 I had to increment the id so I don't override itself.
if (a.ERecordSchedulingID <= c)
{
a.ERecordSchedulingID = a.ERecordSchedulingID++;
}
//save to db
db.ERecordSchedulings.Add(item);
db.SaveChanges();
//item.LicenseNumber = a.LicenseNumber;
//item.State = a.State;
//item.ProviderLicenseID = a.ProviderLicenseID;
}
}
}
if (applicantCapturedData.ProviderLicense != null)
{
if (applicantCapturedData.ProviderLicense.Count() > 0)
{
foreach (var i in providerLicenselist)
{
providerLicense.LicenseNumber = i.LicenseNumber;
providerLicense.State = i.State;
providerLicense.ProviderLicenseID = i.ProviderLicenseID;
i.ApplicantCapturedData_ID = newid;
if (providerLicense.ProviderLicenseID <= c)
{
providerLicense.ProviderLicenseID = providerLicense.ProviderLicenseID++;
}
db.ProviderLicenses.Add(i);
db.SaveChanges();
}
}
}
if (applicantCapturedData.Payor != null)
{
if (applicantCapturedData.Payor.Count() > 0)
{
foreach (var p in payorlist)
{
payor.Pyor = p.Pyor;
payor.PayorID = p.PayorID;
p.ApplicantCapturedData_ID = newid;
if (payor.PayorID <= c)
{
payor.PayorID = payor.PayorID++;
}
db.Payors.Add(p);
db.SaveChanges();
}
}
}
if (applicantCapturedData.PracticeInfoOtherLocations != null)
{
if (applicantCapturedData.PracticeInfoOtherLocations.Count() > 0)
{
foreach (var p in OtherAddressList)
{
otheraddresses.City = p.City;
otheraddresses.Fax = p.Fax;
otheraddresses.Phone = p.Phone;
otheraddresses.State = p.State;
otheraddresses.Street = p.Street;
otheraddresses.Suite = p.Suite;
otheraddresses.ZipCode = p.ZipCode;
otheraddresses.AppID = newid;
otheraddresses.ID = p.ID;
if (otheraddresses.ID <= c)
{
otheraddresses.ID = otheraddresses.ID++;
}
db.PracticeInfoOtherLocations.Add(p);
db.SaveChanges();
}
}
}
if (applicantCapturedData.EPrescribe != null)
{
if (applicantCapturedData.EPrescribe.Count() > 0)
{
foreach (var p in Eprescribelist)
{
eprescribe.EPrescribeOptions = p.EPrescribeOptions;
eprescribe.ID = p.ID;
p.ApplicantCapturedData_ID = newid;
if (eprescribe.ID <= c)
{
eprescribe.ID = eprescribe.ID++;
}
db.EPrescribes.Add(p);
db.SaveChanges();
}
}
}
if (applicantCapturedData.TaxNPITaxonomy != null)
{
if (applicantCapturedData.TaxNPITaxonomy.Count() > 0)
{
foreach (var t in taxlist)
{
tax.GroupNPI = t.GroupNPI;
tax.Notes = t.Notes;
tax.TaxID = t.TaxID;
tax.TaxNPITaxonomyID = t.TaxNPITaxonomyID;
tax.Taxonomy = t.TaxID;
t.ApplicantCapturedData_ID = newid;
if (tax.TaxNPITaxonomyID <= c)
{
tax.TaxNPITaxonomyID = tax.TaxNPITaxonomyID++;
}
db.TaxNPITaxonomies.Add(t);
db.SaveChanges();
}
}
}
return RedirectToAction("Index");
}
return View(applicantCapturedData);
}