The Tools Used: VB.NET 2012, MVC 4, Visual Studio 2012
The Controller: SubmitFormController.vb
Namespace MvcApplication19
Public Class UserNamePrintOutSubmitClassController
Inherits System.Web.Mvc.Controller
' This method will handle GET
Function Technology() As ActionResult
Return View("Technology")
End Function
' This method will handle POST
<HttpPost>
Function UserNamePrintOut() As ActionResult
' Do something
Response.Write("Hello " & Request.QueryString("UserName") & "<br />")
Return View()
End Function
End Class
End Namespace
The View: Technology.vbhtml
The URL: http://localhost/Home/Technology/
<form action="" method="post">
<input type="text" name="UserName" />
<input type="submit" name="UserName_submit" value="Print It Out!" />
</form>
The Question
I do not have a model in this example. The intention is to have the UserName submitted with the submit button and have it printed on the screen, on page load. Which means, the UserName should get passed to the action method and get printed on the screen.
I am having no error messages, nevertheless, the UserName does not get printed on the screen, perhaps, somebody, can have look at the code above.
I have been trying this with tutorials, which are often in C#. My background has been PHP, and I still tend to think in terms of “echo” – yet, I am getting used to MVC 4.
You’re using ASP.NET MVC, not WebForms; however the concept of “postback” is unique to WebForms. It’s like using System.Windows.Forms when you’re actually using WPF.
In MVC you have different methods for each verb, you should rewrite it as follows: