简体   繁体   English

无法从html上的文本框中获取参数

[英]Cannot get the parameter from my textbox on the html

Hi im working right now on a page where you input the id of a person, and if its not in the system then it sends you to the Create , so you can register. 您好,我现在在一个页面上工作,在该页面上您输入了一个人的身份证,如果该号码不在系统中,则它将您发送至Create,因此您可以进行注册。 However 然而

[HttpPost]
public ActionResult ingresarSolicitante(int? id)

doesn't get the id, even if I change it for a string and a textbox, I cannot get the value. 不会获取ID,即使我为字符串和文本框更改了ID,也无法获取该值。 Any ideas? 有任何想法吗?

here is the html 这是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>

and here is the code on the controller 这是控制器上的代码

[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);
}

I dont know whats wrong with the string id on this method that I allways get a null. 我不知道此方法的字符串ID到底出了什么问题,所以我总是得到null。

change textbox name @Html.TextBox("Cedula") to @Html.TextBox("id") 将文本框名称@ Html.TextBox(“ Cedula”)更改为@ Html.TextBox(“ id”)

or change the parameter name of your action method to Cedula 或将操作方法​​的参数名称更改为Cedula

Your Html Page is PageModelBase and you can get your Id from this. 您的HTML页面是PageModelBase,您可以从中获取ID。 Or in other word put that id into the TextBox like: 或者换句话说,将该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>
}

If you do this, you can set and get data from HTML and into HTML 如果执行此操作,则可以设置数据并将其从HTML中获取,并导入HTML中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM