I'm trying to link a method defined in my razor pagemodel to an onclick event. Specifically, I'd like to do this without using extra javascript if possible.
I have the following razor code which fires the onclick event whenever the html is loaded for some reason. After the html is loaded, the onclick event doesn't work when I click something.
<div class="list-group" id="module-list-tab" role="tablist">
@for (int i = 0; i < Model.ModuleModel.Count; i++)
{
var module = Model.ModuleModel[i];
<a class="list-group-item list-group-item-action" data-toggle="list" href="#list-tdc-tags" role="tab" onclick="@Model.UpdateTdcTags(module.ModuleID)">@Html.DisplayFor(indexItem => module.Name)</a>
}
</div>
And I have the following method defined in my pagemodel
public async Task UpdateTdcTags(int moduleId)
{
TdcPointModel = await _context.TdcPoint.Where(x => x.ModuleId == moduleId).ToListAsync();
}
Is it possible to link a PageModel method to an html onclick event? I'm aware that you can use handlers on forms for things like posting/getting, but i'd like to be able to tie other methods in PageModel to different types of html events.