Please I am trying to concatenate values from asp-for textboxes and it is not working.
Can you help me show me how it will work?
My controller action and view code is shown below.
CONTROLLER ACTION
[HttpPost]
[ValidateAntiForgeryToken]
public async Task WorkerIdentity([Bind("Id,FirstName,LastName,CompnyCode,DeptmentCode,IdentificationKey,WorkerIdNo")] WorkerIdentity workerIdentity)
{
if (ModelState.IsValid)
{
WorkId Id = new WorkId();
string? FirstNme = Id.FirstName;
string? CompCode = Id.CompnyCode;
string? DeptCode = Id.DeptmentCode;
string? IdentKey = Id.IdentificationKey;
string WorkerIdentNo = FirstNme + "." + CompCode + "." + DeptCode + "." + IdentKey;
RegistrationKeyId WorkerIdentificationNo = new RegistrationKeyId();
ViewBag.WorkerIdentificationNo = WorkerIdentNo;
_context.Add(workerIdentity);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(workerIdentity);
}
VIEW
@model BootCamp_Opulence.Models.WorkerIdentity
@{
ViewData["Title"] = "Worker Identity";
}
<h4>@ViewData["Title"] </h4>
<div class="row">
<div class="col-md-4">
<form asp-action="WorkerIdentity">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="FirstName" class="control-label"></label>
<input asp-for="FirstName" class="form-control" name="FirstName" />
<span asp-validation-for="FirstName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="LastName" class="control-label"></label>
<input asp-for="LastName" class="form-control" />
<span asp-validation-for="LastName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="CompnyCode" class="control-label"></label>
<input asp-for="CompnyCode" class="form-control" name="CompnyCode" />
<span asp-validation-for="CompnyCode" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="DeptmentCode" class="control-label"></label>
<input asp-for="DeptmentCode" class="form-control" name="DeptmentCode" />
<span asp-validation-for="DeptmentCode" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="IdentificationKey" class="control-label"></label>
<input asp-for="IdentificationKey" class="form-control" value="@ViewBag.WorkerIdKeyNo" name="IdentificationKey" />
<span asp-validation-for="IdentificationKey" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="WorkerIdNo" class="control-label"></label>
<input asp-for="WorkerIdNo" class="form-control" value="@ViewBag.WorkerIdentificationNo" />
<span asp-validation-for="WorkerIdNo" class="text-danger"></span>
</div><br />
<div class="form-group">
<input type="submit" value="Identify" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>