从视图中的表单传递值时在控制器中接收参数 null
我在主页索引页中有一个表单,询问用户想要查看哪个患者,并询问 SSN(社会安全号码)号码,该号码是表 DIAGNOSIS 中的外键。当用户输入 SSN(社会安全号码)并将数据传递给控制器时,应用程序会停止并提示参数不能为空。
<form asp-controller="Diagnosis" asp-action="Index" method="post">
Social Security Number:
<input asp-for="Patient.Email" type="email" style="width:50%;" placeholder="Social Security" >
<button type="submit" class="button" style="padding:10px;">
<i class="bi bi-search"></i>Search
</button>
Name:
<input asp-for="Patient.Name" type="text" style="width:40%;" placeholder="Patient Name">
<button type="submit" class="button" style="padding:10px;">
<i class="bi bi-search"></i>Search
</button>
</form>
控制器
public IActionResult Index(string id)
{
int _id = int.Parse(id);
List<Diagnosis> diagQuery = context.Diagnosis
.Where(d => d.SocialSecurityPatId == _id)
.ToList();
return View(diagQuery);
}
I have a form in the Home index page that ask the user which patient wants to see, and ask for the SSN (Social Security Number) number that is a foreign key in the table DIAGNOSIS. When the user enter the SSN (Social Security Number) and pass the data to the controller the app stops and says parameter cannot be null.
<form asp-controller="Diagnosis" asp-action="Index" method="post">
Social Security Number:
<input asp-for="Patient.Email" type="email" style="width:50%;" placeholder="Social Security" >
<button type="submit" class="button" style="padding:10px;">
<i class="bi bi-search"></i>Search
</button>
Name:
<input asp-for="Patient.Name" type="text" style="width:40%;" placeholder="Patient Name">
<button type="submit" class="button" style="padding:10px;">
<i class="bi bi-search"></i>Search
</button>
</form>
The controller
public IActionResult Index(string id)
{
int _id = int.Parse(id);
List<Diagnosis> diagQuery = context.Diagnosis
.Where(d => d.SocialSecurityPatId == _id)
.ToList();
return View(diagQuery);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论