0

EDIT:

The function "TheColorNameFunction" is working successfully. The question is, how to have the return View() the function has return back to the "TheRequest" View.

SOLVED:

It simply took writing the View name into the return View() as following: return View("TheRequest")


The Controller:

Function TheRequest() As ActionResult

        Return View()
    End Function


    <HttpPost()>
    Function TheColorNameFunction() As ActionResult

        Response.Write("The color you have submitted: " & Request.Form("ColorName"))

        Return View()
    End Function

The HTML:

@Html.BeginForm("TheColorNameFunction", "Home", method:= FormMethod.Post)

<fieldset>
    <input type="text" name="ColorName" />
    <input type="submit" name="ColorName_SubmitButton" />
</fieldset>

The HTML Second:

            <ul id="menu">
                <li>@Html.ActionLink("Home", "Index", "Home")</li>
                <li>@Html.ActionLink("About", "About", "Home")</li>
                <li>@Html.ActionLink("The Request View", "TheRequest", "Home")</li>

            </ul>
user1799026
  • 47
  • 4
  • 11

2 Answers2

3

If I'm understanding your question correctly, this can be accomplished by either using ViewData or a view model. ViewData is simpler to use in your situation.

Using ViewData:

Your action method:

<HttpPost()>
Function TheColorNameFunction(ColorName as String) As ActionResult
    ViewData("message") = "The color you have submitted: " & ColorName
    Return View()
End Function

And in your view you can display the message like this:

@ViewData("message")

UPDATE: Alright, so if I understand correctly you just want to return back to the original view titled "TheRequest", correct? There are two ways you can do that... instead of return View() you can just do return TheRequest(), or if the name of the .vbhtml file is 'TheRequest', you can use return View("TheRequest").

HTX9
  • 1,717
  • 3
  • 15
  • 27
  • The function does work. It is the POST Value which does not return back to the View. I have a "return View()" in the function, yet the View is called "TheRequest". – user1799026 Nov 19 '12 at 06:19
0

I do't know if you are asking how to generate the url of your action, which is explained here: Url.Action parameters?

or if you just want to submit it, in that case you only need:

<input type=submit value="submit" />

you already have your form to post to your action, so a submit button is more than enough.

Did I understood your question correctly?

UPDATE: For the values to be passed just pass an argument in your action like this:

    <HttpPost()>
    Function TheColorNameFunction(colorName as String) As ActionResult

The mechanisms from MVC are smart enough to build a complex object from any field or value that you have in your form

Your action should be written like this:

 @Url.Action("TheColorNameFunction", "Home", "green")
Community
  • 1
  • 1
Jorge Alvarado
  • 2,664
  • 22
  • 33
  • I have edited the question. The question was about "returning it back to the View, after the submit button is pressed". – user1799026 Nov 18 '12 at 17:53
  • The HTML.BeginForm takes over of what you have suggested in the Update you wrote. The View is returned in the function with "return View()", yet the View is called "TheRequest", and that is the View it should return back to. – user1799026 Nov 19 '12 at 06:28