简体   繁体   English

ASP.NET Core MVC 2.1:在不使用Javascript的情况下触发按钮事件

[英]ASP.NET Core MVC 2.1: Fire button events without using Javascript

I have a simple HTML control with a textbox displaying a numeric value and an increment and decrement button 我有一个带有文本框的简单HTML控件,其中显示了一个数值和一个增减按钮

<div class="row">
    <div class="col-md-9">
        <input type="button" value="-" />
        <input asp-for="@pizza.Quantity" />
        <input type="button" value=" + " />
    </div>
    <div class="col-md-3">
      <a href="#">Remove</a>
    </div>
</div>

Behind the scenes, there is an equally simple ViewModel: 在幕后,有一个同样简单的ViewModel:

public class CartViewModel
{
    public int Id { get; set; }
    public string Name { get; set; }
    public decimal Price { get; set; }
    public int Quantity { get; set; }
}

When clicking one of the buttons, the value should be either incremented or decremented. 单击其中一个按钮时,该值应递增或递减。 How would I best go about wiring events to said buttons without using Javascript? 我如何最好地在不使用Java脚本的情况下将事件连接到上述按钮? Is it possible to do so without having to use form elements? 是否可以不必使用表单元素而这样做?

you can use HTML5 or many "bootstrap" controls/plugins 您可以使用HTML5或许多“自举”控件/插件

in this example you have min/max as well 在这个例子中,你也有最小/最大

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_number https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_number

Quantity (between 1 and 5): 数量(1至5之间):

Note: type="number" is not supported in Internet Explorer 9 and earlier versions. 注意: Internet Explorer 9和更早版本不支持type =“ number”。

Bootstrap millions of plugins like https://www.virtuosoft.eu/code/bootstrap-touchspin/ 引导数百万个插件,例如https://www.virtuosoft.eu/code/bootstrap-touchspin/

A html control event could not be executed without the help of javascript. 没有javascript的帮助,无法执行html控制事件。 To achieve events to be fired without JavaScript wireup then the only possible way to use the server side button(asp:button) 要实现无需JavaScript连线即可触发的事件,那么唯一可能使用服务器端按钮(asp:button)的方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM