I have one page that collects the users initials and the entry date. I then pass that to as secondary page where some input work is going to be done but I have not been able to get the initials or entry date to show up in the HTML on the secondary page.
I am passing Initials and the EntryDate from the index page to the Add page with this.
public IActionResult OnPost()
{
if (!ModelState.IsValid)
{
return Page();
}
return RedirectToPage("Add", "User",
new { User.EntryDate, User.Initials});
}
我可以确认,该物体(Initials,enterDate)将其放在第二页,在添加页上设置一个空白点。
public void OnGet(UserModel user)
{
Initials = user.Initials;
EntryDate = user.EntryDate;
}
最后,我可以把初始和出入境从用户物体转到项目标的上,以便在数据提交数据库时将初始和出入境点列入《公报》。
[ViewData]
[BindProperty]
public DateTime EntryDate { get; set; }
[ViewData]
[BindProperty]
public string Initials { get; set; }
public async Task<IActionResult> OnPost()
{
if (!ModelState.IsValid)
{
return Page();
}
Initials = User.Initials;
EntryDate = User.EntryDate;
ItemModel item = new ItemModel();
item.UserId = Initials;
item.TransferDate = EntryDate;
item.ItemNumber = Item.ItemNumber;
item.FromLocation = Item.FromLocation;
item.ToLocation = Item.ToLocation;
item.Quantity = Item.Quantity;
await item.InsertAsync();
return RedirectToPage("/Index");
}
我所挣扎的那部分是,在装满时,我想在添加页的顶端展示起步和起步。
<div class="row">
<div class="col-md-4">
Initials: @Html.DisplayFor(User => User.User.Initials)
<br />
Entry Date: @Html.DisplayFor(User => User.User.EntryDate)
</div>
</div>
我确实注意到“Html”上的初步和入境情况。 当我袭击波斯特时,显示器。 我的问题是,我想在OnGet上显示(在该页的表格上出现任何数据之前,在Add页上)。
我认识到,我公布守则的方式可能令人困惑,因此,我现在要把整页放在现在的位置上。
public class AddModel : PageModel
{
[ViewData]
[BindProperty]
public DateTime EntryDate { get; set; }
[ViewData]
[BindProperty]
public string Initials { get; set; }
[BindProperty]
public ItemModel Item { get; set; }
[BindProperty]
public UserModel User { get; set; }
public void OnGet(UserModel user)
{
Initials = user.Initials;
EntryDate = user.EntryDate;
}
public async Task<IActionResult> OnPost()
{
if (!ModelState.IsValid)
{
return Page();
}
Initials = User.Initials;
EntryDate = User.EntryDate;
ItemModel item = new ItemModel();
item.UserId = Initials;
item.TransferDate = EntryDate;
item.ItemNumber = Item.ItemNumber;
item.FromLocation = Item.FromLocation;
item.ToLocation = Item.ToLocation;
item.Quantity = Item.Quantity;
await item.InsertAsync();
return Page();
//return RedirectToPage("/Add");
//return RedirectToPage("/Index");
}
}