0

The intention is to access a module in a controller, and that by pressing the button.

So a HelloWorld message does get printed on the screen.

The Directory Structure


  • models/HelloWorldController.vb
  • views/Home/FrontPage.vbhtml
  • views/_ViewStart.vbhtml
  • views/Shared/_Layout.vbhtml

The Example Code


FrontPage.vhtml

<h1>Cause the HelloWorld Line...</h1>

<form name="hello_world_button" action="" method="post">
    <button type="button" name="button">Press it!</button>
</form>

HelloWorldController.vb

Module HelloWorld
    ' Every console application starts with Main
    Sub Main()
        System.Console.WriteLine("Hello world!")

    End Sub
End Module

The Tools Used


Visual Studio 2012, Visual Basic, MVC 4

Further Addendum


For those who are wondering, here is a showcase of the intended HelloWorld application with PHP - (PHP has been my background in regards to programming)

<body>
    <form action="" method="POST">
        <button name="button">Press It!</button>
    </form>


    <?php
    $button = $_POST['button'];

    if(isset($button)) {
        echo "Hello World Message!";
        }
    ?>

</body>

Here is an example to have a look at: click here

The URL Routing


I am as of yet focused on "routing" and the "http" protocol system with VB.NET.

I tried the following:

<h1>Cause the HelloWorld Line...</h1>

<form name="hello_world_button" action="@Url.Action("HelloWorld", "~/~/Models/HelloWorldController.vb")" method="post">
    <button type="button" name="button">Press it!</button>
</form>

The HTML action attribute holds the url.action command with the module name HelloWorld and the path to the controller file.

Though, when pressing the button the message does not get printed on the screen.

Is there a way to check if the routing has been correct?

1 Answers1

0

You do not need to fill out action attribute of the web form.

Source: ASP.NET Form Processing Basics

The action attribute of the tag has been removed entirely; ASP.NET takes care of adding it for us when it processes the tag.

Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151
  • From the article you linked to it showcases the `runat="server"` command. Whereas I am looking to have the `module` in the controller to be called up. I am not sure how .NET does handle this, yet there may be no need to switch the URL to the script file. Simply calling up the script (rather the module) without having the URL to switch may be enough - if .NET is not already doing it. – user1778219 Nov 01 '12 at 02:48
  • @user1778219: I am a WinForms programmer. But I was under the impression MVC is based on ASP.NET, so everything should work similarly. Could you please elaborate on your problem in the question? – Victor Zakharov Nov 01 '12 at 11:24
  • It is a getting started question. I am looking to call up the module in the controller. – user1778219 Nov 01 '12 at 15:57
  • @user1778219: Are you looking for [something like this](http://stackoverflow.com/questions/6972521/how-do-i-execute-a-controller-action-from-an-httpmodule-in-asp-net-mvc)? – Victor Zakharov Nov 01 '12 at 18:06
  • It is indeed like that, the "HelloWorld" message should be printed after having the button pressed. (Do keep in mind, it is a getting started question.) Though, I can understand you guys are focusing on the "http" protocol system a lot. My background has been PHP, thus I would focus on the "action" attribute of the form tag, quite a bit. – user1778219 Nov 01 '12 at 18:36