I need to save IDs that pass through the url
I need to capture that "1009" value and take it to a
<input name="codigo" type="text"class="form-control" value="AQUI
NECESITO QUE ESTE ESE VALOR DE LA URL"/>
I need to save that value in a variable.
My sight
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>tb_familiares</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.nombres, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.nombres, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.nombres, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.documento_identidad, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.documento_identidad, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.documento_identidad, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.fecha_nacimiento, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.fecha_nacimiento, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.fecha_nacimiento, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.sexo, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.sexo, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.sexo, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.parentesco, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.parentesco, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.parentesco, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.celular, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.celular, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.celular, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.telefono, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.telefono, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.telefono, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.cod_colaborador, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
// HERE IS WHERE I WANT THAT INPUT WITH THAT ID //
@Html.EditorFor(model => model.cod_colaborador, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.cod_colaborador, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
My controller
namespace WebApplicationSIOldMutual.Controllers
{
public class familiaresController : Controller
{
private sioldmutualEntities db = new sioldmutualEntities();
// GET: familiares
public ActionResult Index()
{
return View(db.tb_familiares.ToList());
}
// GET: familiares/Details/5
public ActionResult Details(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
tb_familiares tb_familiares = db.tb_familiares.Find(id);
if (tb_familiares == null)
{
return HttpNotFound();
}
return View(tb_familiares);
}
// GET: familiares/Create
public ActionResult Create()
{
return View();
}
// POST: familiares/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id_familiar,nombres,documento_identidad,fecha_nacimiento,sexo,parentesco,celular,telefono,cod_colaborador")] tb_familiares tb_familiares)
{
if (ModelState.IsValid)
{
db.tb_familiares.Add(tb_familiares);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(tb_familiares);
}
// GET: familiares/Edit/5
public ActionResult Edit(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
tb_familiares tb_familiares = db.tb_familiares.Find(id);
if (tb_familiares == null)
{
return HttpNotFound();
}
return View(tb_familiares);
}
// POST: familiares/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "id_familiar,nombres,documento_identidad,fecha_nacimiento,sexo,parentesco,celular,telefono,cod_colaborador")] tb_familiares tb_familiares)
{
if (ModelState.IsValid)
{
db.Entry(tb_familiares).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(tb_familiares);
}
// GET: familiares/Delete/5
public ActionResult Delete(int? id)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
tb_familiares tb_familiares = db.tb_familiares.Find(id);
if (tb_familiares == null)
{
return HttpNotFound();
}
return View(tb_familiares);
}
// POST: familiares/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
tb_familiares tb_familiares = db.tb_familiares.Find(id);
db.tb_familiares.Remove(tb_familiares);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
db.Dispose();
}
base.Dispose(disposing);
}
}
}
My route file
namespace WebApplicationSIOldMutual
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
}
I'm pretty new at asp.net mvc5.