I have two controllers, each with a Save
method.
public ActionResult SaveContract(Contract contract)
{
//code shortened for brevity
int id = Convert.ToInt32(cmd.Parameters["@OBJECTID"].Value);
return RedirectToAction("SaveContractDetails", "ContractDetails", id);
}
and I am redirecting to SaveContractDetails
method in ContractDetails
controller. What I am trying to do is send the id
of the Contract
model to the SaveContractDetails
method in the ContractDetails
controller, like so:
public IActionResult SaveContractDetails(ContractSettlementDetail contractSettlementDetail, int id)
{
return View();
}
The thing is, the id
in the SaveContractDetails
method is 0
. I suppose I can't send it the way I am trying to. I'd really want to avoid catching the id
with javascript somehow and sending it to the method with an ajax
. How should I proceed, any advice for this intern?
Just send your route values this way => new { id = id }
and it will work
public ActionResult SaveContract(Contract contract)
{
int id = Convert.ToInt32(cmd.Parameters["@OBJECTID"].Value);
return RedirectToAction("SaveContractDetails", "ContractDetails", new { id = id });
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments