user2067567
user2067567

Reputation: 3803

Passing Data from One View to Another view in MVC

Am searching for answers for Passing Data from One View to Another view in MVC but may be i did not find the correct link and posting here.

I have Controller A mapping to view A
I have Controller B mapping to view B

From View A i need to pass a Textbox value to View B.

One option i see in common is

@Url.Action("Index", "B", new { test = testName})

But this one will show the data in URL. I don want to do that

But am looking for any alternative approach. Any suggestions ?

Thanks

Upvotes: 0

Views: 4779

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038720

You could use an HTML form that will submit the value of the textbox to the second controller:

@using (Html.BeginForm("index", "b", FormMethod.Post))
{
    @Html.TextBoxFor(x => x.SomeValue)
    <button type="submit">OK</button>
}

Since we are using a POST request the value will be sent in the body of this request and it will not be part of the resulting query string.

Upvotes: 2

Related Questions