[英]Cannot get the parameter from my textbox on the html
您好,我现在在一个页面上工作,在该页面上您输入了一个人的身份证,如果该号码不在系统中,则它将您发送至Create,因此您可以进行注册。 然而
[HttpPost]
public ActionResult ingresarSolicitante(int? id)
不会获取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到底出了什么问题,所以我总是得到null。
将文本框名称@ Html.TextBox(“ Cedula”)更改为@ Html.TextBox(“ id”)
或将操作方法的参数名称更改为Cedula
您的HTML页面是PageModelBase,您可以从中获取ID。 或者换句话说,将该id放入TextBox中,例如:
@model Entrega02Programacion03.Models.Solicitante
@{
ViewBag.Title = "ingresarSolicitante";
}
<h2>ingresarSolicitante</h2>
<div>
@using (Html.BeginForm())
{
<p>
Buscar Solicitante por celuda: @Html.TextBox(Model.Id)<br />
<input type="submit" value="Filtrar" />
</p>
}
如果执行此操作,则可以设置数据并将其从HTML中获取,并导入HTML中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.