vendredi 13 mars 2020

How to call action from checkbox input using tag helpers

If I want to call controller action using input of type image I can do it like:

<form method="post">
    <button asp-controller="Home" asp-action="Index">Click Me</button>
    <input type="image" src="..." alt="Or Click Me" asp-controller="Home" 
                                asp-action="Index">
</form>

Is it possible to do something similar with input of type checkbox using tag helpers like this:

<input type="checkbox" asp-for="@item.Property" asp-controller="Home" asp-action="DoSomething" asp-route-propertyId="@item.Id" class="form-control" />

? Or if I must write own custom tag helper for this?

Code below also does not work.

<input type="checkbox" asp-for="@item.Property" onclick="@Url.Action("DoSomething", "Home", new { propertyId= item.Id })" class="form-control" />



Aucun commentaire:

Enregistrer un commentaire