I have a razor view in which a person's information are displayed, it route is https://localhost:PORT/Pesron/Details/E-12345.
I want to create a profile for the said person using another controller, the corresponding link would be https://localhost:PORT/Profile/Create/E-12345.
The page would open normally, but I would like getting the value E-123456 which is the person's ID and obviously changes from one to another, into a (disabled) input box in Create, so when I fill other information and press submit, a new profile is created, I am doing it using MVC controller but wouldn't mind using Web API too.
How I open Create in Person's Details view.
<a asp-action="Create" asp-controller="Profile" asp-route-id="@Model.ID">Create</a>
My 2 Create action methods.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create(string MRN, [Bind("Id,Dep_Id,Check_In,Check_Out")] Profile profile)
{
ViewData["ID"] = MRN;
if (ModelState.IsValid)
{
_context.Add(profile);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(profile);
}
public IActionResult Create(string MRN)
{
ViewData["ID"] = MRN;
return View();
}
Could the reason be that the value I am sending is not the primary key, I made it hidden and auto incrementing.
asp-route-MRN="@Model.ID". Change your code to<a asp-action="Create" asp-controller="Profile" asp-route-MRN="@Model.ID">Create</a>Bind()have anything to do with it?