TagHelper in ASP.NET Core doesn’t update values

TagHelper in ASP.NET Core doesn't update values

When I click on the link save Order I want the site to be redirected to
.../saveOrders?trans=[selected value]&quant=[selected value]
instead the site always redirects to .../saveOrders?quant=
no matter which values I type in for the parameters.

I am using MVC and TagHelpers:

Here is a snippet of the view for the picture:

<div class="col-md-3">
    <form asp-action="CreateOrder">
        <div class="form-group">
            <label asp-for="TransactionType"class="control-label">Transaction Type</label>
            <select asp-for="TransactionType" class="form-control">
                <option value="">Select Transaction Type</option>
                <option value="B">BUY</option>
                <option value="BD">BUY DURCHLIEFERUNG/UMLEGUNG</option>
                <option value="S">SELL</option>
                <option value="SD">SELL DURCHLIEFERUNG/UMLEGUNG</option>
            </select>
            <span asp-validation-for="TransactionType" class="text-danger"></span>
        </div>
    </form>
</div>
@*Eingabe*@
<div class="col-md-3">
    <form asp-action="CreateOrder">
        <div class="form-group">
            <label asp-for="Quantity" class="control-label">Quantity</label>
            <input asp-for="Quantity" class="form-control" />
            <span asp-validation-for="Quantity" class="text-danger"></span>
        </div>
    </form>
</div>

<div>
<a href="javascript:void(0);" onclick="history.go(-1);">Back to List</a>
<a asp-controller="Order" asp-action="saveOrders" asp-route-transaction="@Model.TransactionType" asp-route-quant="@Model.Quantity" >Save Order</a>

Here is my model:

public class CreateOrderModel
{
    public CreateOrderResponse1 CreateOrderResponse1 { get; set; }
    public SaveOrderResponse1 SaveOrderResponse1 { get; set; }
    public bool Save { get; set; }
    public long InstrumentId { get; set; }
    public string instName { get; set; }
    public string securCode { get; set; }
    public string currency { get; set; }
    public long Exchange { get; set; }
    public double Price { get; set; }
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
    [DataType(DataType.Date)]
    public DateTime quoteDate { get; set; }
    public double nominal { get;set; }
    public long code { get; set; }
    public string pName { get; set; }
    [Required]
    public string TransactionType { get; set; }
    [Required]
    public double Quantity { get; set; }

    public string strategyCode { get; set; }

    
    
    public string LastAction { get; set; }
   
    
  
    public string comment { get; set; }

and here is the Controller saveOrders which I am trying to call through the click on saveOrder.

public async Task<IActionResult> saveOrders(string transaction, double quant)
    {
        saveOrder.TransactionType = transaction;
        saveOrder.Quantity = quant;
        saveOrder.Save = true;
        await saveOrder.OnCreateOrder();
        return View(saveOrder);
    }

When I call the Controller function SaveOrders from the view the parameters null and 0 are passed for transaction and quant, no matter what I select.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You use two forms, but every form do not have the button of submmit. You can try to add javascript to edit the url of Save Order.

Here is an exmple. When click Save Order , edit its href.

<a onclick="save()" id="saveorder" asp-controller="Order" asp-action="saveOrders" asp-route-transaction="@Model.TransactionType" asp-route-quant="@Model.Quantity">Save Order</a>

@section Scripts{ 
<script>
    function save() {
        var transaction = document.getElementById('TransactionType').value
        var quant = document.getElementById('Quantity').value
        console.log(transaction, quant)
        document.getElementById('saveorder').href = '/Order/saveOrders?transaction=' + transaction + '&quant=' + quant
    }
</script>
}

Then I select BUY.

TagHelper in ASP.NET Core doesn't update values

Get it in this action.

TagHelper in ASP.NET Core doesn't update values


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x