PNRT
asked on
Get vbhtml code to execute from html - razor
Hi Experts.
I have code in the code section of my vbhtml, say
dim a as integer
dim b as integer
dim result as integer = a + b
a and b are dynamic so I want to add a button to the html that will show "result" in a label when the
button is clicked to update result
I think I'm trying to say I want an html button that will activate code
Any Ideas?
I have code in the code section of my vbhtml, say
dim a as integer
dim b as integer
dim result as integer = a + b
a and b are dynamic so I want to add a button to the html that will show "result" in a label when the
button is clicked to update result
I think I'm trying to say I want an html button that will activate code
Any Ideas?
ASKER
Many thanks, I get the input boxes and the submit button which I assume adds up a and b, but how would I show "result" on the page. I don't get result when clicking the button. I have this so far Thanks again
dim a As Integer = Request.Form("valueA")
dim b As Integer = Request.Form("valueB")
dim result as integer = a + b
<form>
<input name="valueA">
<input name="valueB">
<input type=submit>
</form>
dim a As Integer = Request.Form("valueA")
dim b As Integer = Request.Form("valueB")
dim result as integer = a + b
<form>
<input name="valueA">
<input name="valueB">
<input type=submit>
</form>
<div>@{result}</div>
ASKER
No luck I'm afraid.
@result shows zero when the page loads.
Entering values and clicking refreshes the page, empties a and b boxes and then still shows zero
Maybe the page refresh is a problem?
@result shows zero when the page loads.
Entering values and clicking refreshes the page, empties a and b boxes and then still shows zero
Maybe the page refresh is a problem?
Try this:
In your controller:
In your Index.vbhtml:
In your controller:
Public Function Index(ByVal a As Integer?, ByVal b As Integer?) As ActionResult
dim a as integer
dim b as integer
dim result as integer = a + b
Return View(result)
End Function
In your Index.vbhtml:
@ModelType Integer
....
<div>@{Model}</div>
ASKER
Sorry, how would I call the function?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<input name="valueA">
<input name="valueB">
<input type=submit>
</form>
and in your code:
a = Request.Form("valueA");
b = Request.Form("valueB");
dim result as integer = a + b;
Untested code, just a crude guideline to where you seem to be going