1 回答
TA贡献1847条经验 获得超11个赞
您应该将 OnGet 方法传递的数据保留在视图中(如hidden controls),然后将它们传递给 OnPost 方法,而 OnPost 方法需要receive parameter从视图中获取 OnGet 方法中的数据。
我创建了一个简单的演示供您参考:
[BindProperty]
public Employee Employee { get; set; }
public void OnGet()
{
Employee = new Employee()
{
Id = 1,
Name = "aaaa"
};
nExpenses = 1;
}
public void OnPost(Employee employee)
{
}
看法:
@page
@model WebApplication_core_razorpage.Pages.CodeSampleModel
@*
For more information on enabling MVC for empty projects, visit http://go.microsoft.com/fwlink/?LinkID=397860
*@
<form method="post">
@Html.HiddenFor(model => model.Employee.Id)
@Html.HiddenFor(model => model.Employee.Name)
<input id="Button1" type="submit" value="button" />
</form>
员工类别:
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
}
- 1 回答
- 0 关注
- 84 浏览
添加回答
举报