简体   繁体   中英

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. 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. Any ideas?

here is the 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.

change textbox name @Html.TextBox("Cedula") to @Html.TextBox("id")

or change the parameter name of your action method to Cedula

Your Html Page is PageModelBase and you can get your Id from this. Or in other word put that id into the TextBox like:

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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