.net显示html文本,.net c# 无法从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";

}

ingresarSolicitante

@using (Html.BeginForm())

{

Buscar Solicitante por celuda: @Html.TextBox("Cedula")

}

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.

Talk1:

cedula != id. Use @Html.TextBox("Cedula", null, new { @id = "Id" }) instead

Talk2:

If your model contains an Id column. Then, you can use @Html.TextBoxFor("Id"). You'll need to clear up the comfusion between the string and int in your parameters. Either, one or the other. You might need to cast it, if necessary. The TextBoxFor, lets you tell it what property you want it to use from your model. When it gets posted the Id is passed in the model.

Solutions1

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

or change the parameter name of your action method to Cedula

Talk1:

Hi don't forget to mark this answer is correct

Solutions2

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";

}

ingresarSolicitante

@using (Html.BeginForm())

{

Buscar Solicitante por celuda: @Html.TextBox(Model.Id)

}

If you do this, you can set and get data from HTML and into HTML

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值