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
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 don't generally have a querystring value when POSTing content. If you don't want to automatically bind form values, use the FormCollection, like this:
<HttpPost>
Function UserNamePrintOut() As ActionResult
' Do something
Response.Write("Hello " & FormCollection("UserName") & "<br />")
Return View()
End Function
Darrell Norton, MVP
Darrell Norton's Blog Please click "Mark as Answer" if this helped you.
with your suggestion I have gotten this error message:
Error 24 'FormCollection' is a type and cannot be used as an expression.
ignatandrei,
with your suggestions I have gotten these error messages:
Error 24 'View' is a type and cannot be used as an expression.
Error 26 'ResultExecutedContext' is a type and cannot be used as an expression.
Error 27 Comma or ')' expected.
Error 28 'vm' is not declared. It may be inaccessible due to its protection level.
Error 29 'View' is a type and cannot be used as an expression.
Error 30 'm' is not declared. It may be inaccessible due to its protection level.
DarrelNorton,
when the text is submitted with the submit button through the "textbox", where exactly is it "send" through, or in other words, where is it "passed" through?
So by this, all it would technically take, is to have it requested, and printed out, as in "written out"`?
Performs an HTTP POST request on the supplied url.
zevian
0 Points
38 Posts
Print Text on Submit - MVC 4
Nov 06, 2012 07:28 AM|LINK
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 NamespaceThe View: Technology.vbhtml
The URL:
<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.
DarrellNorto...
All-Star
86805 Points
9644 Posts
Moderator
MVP
Re: Print Text on Submit - MVC 4
Nov 06, 2012 09:17 AM|LINK
You don't generally have a querystring value when POSTing content. If you don't want to automatically bind form values, use the FormCollection, like this:
<HttpPost> Function UserNamePrintOut() As ActionResult ' Do something Response.Write("Hello " & FormCollection("UserName") & "<br />") Return View() End FunctionDarrell Norton's Blog
Please click "Mark as Answer" if this helped you.
ignatandrei
All-Star
135174 Points
21682 Posts
Moderator
MVP
Re: Print Text on Submit - MVC 4
Nov 06, 2012 09:21 AM|LINK
Add a class, name ViewModel. Add a property named UserName{get;set;} and a field named Result
in
Function Technology() As ActionResult
Return View(new ViewModel(){ UserName = "Technology" , Result="BBBBBBBBB"})
End Function
[HttpPost]
Function Technology(ViewModel vm) As ActionResult
vm.Result ="AAAAAAAAA";
Return View(vm)
End Function
in the view
@model ViewModel
@Model.Result
<form action="" method="post">
<input type="text" name="UserName" />
<input type="submit" name="UserName_submit" value="Print It Out!" /> </form>
</form>
Please , please read some tutorials from http://www.asp.net/mvc
zevian
0 Points
38 Posts
Re: Print Text on Submit - MVC 4
Nov 06, 2012 07:07 PM|LINK
DarrelNorton,
with your suggestion I have gotten this error message:
ignatandrei,
with your suggestions I have gotten these error messages:
DarrelNorton,
when the text is submitted with the submit button through the "textbox", where exactly is it "send" through, or in other words, where is it "passed" through?
So by this, all it would technically take, is to have it requested, and printed out, as in "written out"`?
If you may have a link here: http://php.net/manual/en/function.http-post-data.php
It are PHP terms of thinking, ín which I have been thinking of this, where I also did think of it in terms of the superglobal: $_POST['UserName']
Simply, as an example.
As a reminder: VB.NET, MVC 4, Visual Studio 2012