[英]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.