Add custom field to order

1 week ago
I've been trying to add a simple text field to the Order table which can be edited in the admin panel.

I've ran a script to add the 'LeadTime' column to the 'Order' table.
(ALTER TABLE public."Order" ADD LeadTime citext NULL)

I've included the property in the Order Models:
public class Order : BaseEntity
{
   public string LeadTime{ get; set; }
}
public class OrderModel: BaseNopEntityModel
{
   public string LeadTime{ get; set; }
}

I've added this method to the OrderController.cs file:
[HttpPost]
public virtual async Task<IActionResult> UpdateLeadTimeAsync(int orderId, string leadTime)
{
    // Fetch the order from the database
    var order = await _orderService.GetOrderByIdAsync(orderId);

    // Update the LeadTime
    order.LeadTime = leadTime;

    // Save changes to the database
    await _orderService.UpdateOrderAsync(order);

    // Redirect to the order details page or return JSON response as needed
    return RedirectToAction("Details", new { id = orderId });
}

In the _OrderDetails.Info.cshtml view, I've added an input field and button for the 'LeadTime' value:

<div class="form-group row">
    <div class="col-md-3">
        <nop-label asp-for="CreatedOn" />
    </div>
    <div class="col-md-9">
        <div class="form-text-row">@Model.CreatedOn</div>
    </div>                
</div>          
<div class="form-group row">
    <div class="col-md-3">
        <nop-label asp-for="LeadTime" />                    
    </div>
    <div class="col-md-9">
        <form id="updateLeadTimeForm" method="post" action="@Url.Action("UpdateLeadTimeAsync", "Order")">
            <input type="hidden" name="orderId" id="orderId" value="@Model.Id" />
            <input type="text" asp-for="LeadTime" class="form-control" />
            <button type="submit" name="btnSaveLeadTime" id="btnSaveLeadTime" class="btn btn-primary mt-1">
                Save LeadTime
            </button>
        </form>
    </div>
</div>

I've manually entered a value in the field in the database, and the value does get seen by the view and displays it in the input field, but I'm having trouble saving back to the DB when I click the save button.

I just get an error 400 : This page isn't working.
My breakpoint in my controller is not reached, so I must be doing something wrong before the code reaches the controller

No Idea where I'm going wrong.
1 week ago
"this page isn't working," indicates a client-side issue.   Use the browser developer console to inspect the form element.
Does the URL look ok?
Also check the console tab to see if any errors when you click the save button.
1 week ago
I couldn't figure out what the problem was. So I went a different route.

I replicated what was done in the Shipping Method field for the view.

Added my own controller (also a replica of shipping method edit).