首页 > 解决方案 > 无法从我的 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 有什么问题,我总是得到一个空值。

标签: c#asp.net-mvcentity-framework

解决方案


将文本框名称 @Html.TextBox("Cedula") 更改为 @Html.TextBox("id")

或将您的操作方法的参数名称更改为 Cedula


推荐阅读