Link to home
Start Free TrialLog in
Avatar of PNRT
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?
Avatar of Jeroen Timmermans
Jeroen Timmermans
Flag of Netherlands image

<form>
<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
Avatar of PNRT
PNRT

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>
<div>@{result}</div>
Avatar of PNRT

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?
Try this:
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

Open in new window


In your Index.vbhtml:
@ModelType Integer
....
<div>@{Model}</div>

Open in new window

Avatar of PNRT

ASKER

Sorry, how would I call the function?
ASKER CERTIFIED SOLUTION
Avatar of Jeroen Timmermans
Jeroen Timmermans
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial