c# - 无法从我的 html 文本框中获取参数
问题描述
嗨,我现在在一个页面上工作,您可以在其中输入一个人的 id,如果它不在系统中,那么它会将您发送到 Create ,因此您可以注册。然而
[HttpPost]
public ActionResult ingresarSolicitante(int? id)
没有得到 id,即使我将它更改为字符串和文本框,我也无法得到值。有任何想法吗?
这是html
@model Entrega02Programacion03.Models.Solicitante
@{
ViewBag.Title = "ingresarSolicitante";
}
<h2>ingresarSolicitante</h2>
<div>
@using (Html.BeginForm())
{
<p>
Buscar Solicitante por celuda: @Html.TextBox("Cedula")<br />
<input type="submit" value="Filtrar" />
</p>
}
</div>
这是控制器上的代码
[HttpPost]
public ActionResult ingresarSolicitante(string id)
{
// busco el solicitante
Solicitante solicitante = db.Solicitante.Find(id);
//si exite voy a crear expediente
if (solicitante != null)
{
TempData["solicitante"] = solicitante;
return RedirectToAction("InformeSolicitante");
}
// si no me redirije a crear solicitante
else
{
return RedirectToAction("Create");
}
}
// GET: Solicitantes/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Solicitante solicitante = db.Solicitante.Find(id);
if (solicitante == null)
{
return HttpNotFound();
}
return View(solicitante);
}
我不知道这个方法上的字符串 id 有什么问题,我总是得到一个空值。
解决方案
将文本框名称 @Html.TextBox("Cedula") 更改为 @Html.TextBox("id")
或将您的操作方法的参数名称更改为 Cedula
推荐阅读
- css - 如何将文本装饰添加到我的 Angular Material mat-form-field?
- c - 如何检查程序是否在c中静态编译
- c++ - SetTextColor 不改变命令行文本颜色
- javascript - jQuery 事件:keypress 不适用于 Firefox 或 IE,并且 keyup 不适用于 IE
- c - 为什么子进程在使用来自父输出的 stdin 的 fork 和管道时正在等待?
- matlab - 在Matlab中计算图像段之间的接触长度
- c - C:数组中的最后一个元素覆盖所有先前的元素
- c - C:未定义的对“时钟()”的引用
- javascript - rcarousel如何合并jquery语句
- kubernetes - 无法在 k8s 1.13 中挂载本地 PersistentVolume