English 中文(简体)
第一页后第二页的显示值
原标题:Show value on a second razor page passed from the first

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");
    }
}
问题回答

根据您的描述, 您看来是直接到<代码>上的大麻。 添加页,附一些数值,然后加载 加上这些价值观的页数最终从这些数值中得出,我为复制你的问题创造了一个mo,希望能够给你一些帮助。

        [BindProperty]
        public UserModel User { get; set; }

        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

            return RedirectToPage("Add",
                new { User.EntryDate, User.Initials });
        }

Add.cshtml.cs

public class AddModel : PageModel
    {
       
        [BindProperty]
        [FromForm]
        public ItemModel Item { get; set; } = new ItemModel();

        public void OnGet(string Initials, DateTime EntryDate)
        {
            Item.Initials = Initials;
            Item.EntryDate = EntryDate;
        }

        public void OnPost()
        {
            // do some actions......
        }
    }

Add.cshtml

@page
@model RazorP.Pages.AddModel
@{
}

<form method="post">
    <div asp-validation-summary="ModelOnly" class="text-danger"></div>
    <div class="row">
        <div class="col-md-4">
            Initials: @Html.DisplayFor(x=>x.Item.Initials)
            <input type="hidden" asp-for="Item.Initials" />
            <br />
            Entry Date: @Html.DisplayFor(x=>x.Item.EntryDate)
            <input type="hidden" asp-for="Item.EntryDate" />
        </div>
    </div>

    <div class="form-group-with-label login-input-password mb-2">
        <label>Age</label>
        <input class="form-control-input" asp-for="Item.Age" autocomplete="off" />
        <span class="fa fa-eye"></span>
        <span asp-validation-for="Item.Age" class="text-danger"></span>
    </div>

    <div class="form-group-with-label login-input-password mb-2">
        <label>Address</label>
        <input  class="form-control-input" asp-for="Item.Address" autocomplete="off" />
        <span class="fa fa-eye" ></span>
        <span asp-validation-for="Item.Address" class="text-danger"></span>
    </div>
    <button>Submit</button>
</form>

“entergraph





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签