#ASP.NET MVC cshtml event handling

1 messages · Page 1 of 1 (latest)

tender tiger
#

I'd like to create div-onclick handler, that also takes numeric id of it, but I can't understand how to make it
the only solution I fund, is to change extension to .razor, from .cshtml, but if I do that, it brakes my @model imports and all other things

<div class="question-header" id="question-@i" onclick="@OnQuestionClick(@i)">
@functions {
    void OnQuestionClick(int index)
    {
        Console.WriteLine("da");
    }
}```
stuck vapor
#

can't u just accept a parameter ?
void OnQuestionClick(int id)

tender tiger
#

if I remove @ from function in onclick=, then I get this:

stuck vapor
#

maybe something like <div class="question-header" @onclick="@((e) => OnQuestionClick(i))" id="question-@i">

tender tiger
#

in .cshtml - @onclick will try to find variable with that name

stuck vapor
#

oof

tender tiger
#

ASP.NET mvc, can't use function in event

tender tiger
#

Little update

I found way, to trigger Get/Post requests

@using (Html.BeginForm("login", "Account", FormMethod.Post))
{
    Model.Name = "Itan";
    <button type="submit">Login</button>
}```
and that'll trigger them without url changes, as I want
but, I can use it only for `<button type="submit">`

is there way, to make more agile requests ? with not only Get/Post, and not only from button