I'm pretty new in ASP.NET Razor, and i'm trying to establish a very simple thing, so far unsuccessfully.
I have a button, and input field in the HTML. What i want is to call a C# function with the input field's text, when i click on the button.
I can call the function, but i cannot pass the parameter. How could i refer to the text in this input field?
I have searched on the internet, but i haven't found a simple solution. Are there any? I though something like this one:
<input id="Text1" name="Text1" type="text" />
<input id="Button1" type="button" value="button" onclick="@{Class1.Myfunction(Text1.InnerText);}" />
Thank you!
Edit(solved):
Thanks to Sam's comment, i was able to pass parameters to my C# function in another class. I have put the following code to the top to catch POST params:
@{
if (IsPost)
{
Class1.Myfunction(Request.Form["Text1"]);
}
}
When sending the form from the razor website, it will pass the Text1 field value to the C# function.
<form method="post">
<input id="Text1" name="Text1" type="text" />
<input id="Submit1" type="submit" value="submit" />
</form>
Thanks a lot!