我有剃刀页
<form method="post" >
<input type="text" style="display:none;" name="Id"
value="@Model.Employee.ID" />
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" value="@Model.Employee.FirstName"
name="name" id="name" placeholder="Enter Name">
</div>
<br />
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" value="@Model.Employee.Email"
name="email" id="email" aria-describedby="emailHelp"
placeholder="Enter email">
</div>
<br />
<div class="form-group">
<label for="email">Mobile</label>
<input type="text" class="form-control" value="@Model.Employee.Mobile"
name="mobile" id="mobile" aria-describedby="emailHelp"
placeholder="Enter email">
</div>
<br />
<button type="submit" class="btn btn-primary">A</button>
</form>
当我发布public void时OnPost()不触发?
任何理由。
public void OnPost()
{
var emp = new DTO.Employee();
emp.EmployeeId = Request.Form["Id"].ToString();
emp.FirstName = "";
emp.LastName = "";
emp.MotherName = "";
emp.SecondName = "";
emp.MaterialStatus = "";
emp.Gender = "";
emp.ForeignFirstName = "";
emp.ForeignLastName = "";
emp.ForeignSecondNamee = "";
emp.ForeignThirdNamee = "";
emp.IsDeleted = true;
emp.Nationality = "";
emp.NoBrothersAllowed = false;
emp.ThirdName = "";
emp.Phone = "";
emp.PassportNumber = "";
emp.Mobile = Request.Form["mobile"].ToString();
emp.Email = Request.Form["Email"].ToString();
emp.FirstName = Request.Form["name"].ToString();
//emp.ID = int.Parse(Request.Form["Id"].ToString());
EmployeeService.Update(emp);
Response.Redirect("Index1");
}
1条答案
按热度按时间ttp71kqs1#
当我发布public void时OnPost()不触发?
实际上,它不会触发,因为你已经绑定了表单与强类型模型,这是
@Model.Employee.ID
,所以当你发送请求,它没有找到匹配的模型,你没有得到任何东西。你应该在页面上定义你的模型,这将解决你的问题。正确的方法应该如下:
cshtml.cs:
型号:
cshtml:
输出:
**注:**如果您想了解更多关于Razor Page Form提交的详细信息,您可以在这里查看我们的官方文件。