Sent (Pass) TextBox value from one View to another in ASP.Net Core MVC

trisetia302
 
on Sep 22, 2021 07:03 AM
696 Views

Hi,

How to sent value from textbox to another textbox in differen view .Net Core Mvc

I tried to get value on textbox and then send that value to another textbox in differen view. How to do that ? Any help could be appriciate.

The scanario is like this :

1. I have name view as view 1 inside the view 1 I have textbox 

<input type="text" id="parameter1" name="parameter1" class="form-control">

2. And then I have name view as view 2 inside the view 2 I have textbox 

<input type="text" id="parameter1" name="parameter1" class="form-control"> with the same name but placed on differen view.

I want is when action in view 1 doing, the value on textbox in view 1 will sent to destination form in view 2 and populate to textbox in view 2.

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Sep 22, 2021 07:05 AM

Refer below code.

public class HomeController : Controller
{
    // GET: Home
    public IActionResult Index()
    {
        return View();
    }
 
    [HttpPost]
    public IActionResult Greetings(string name)
    {
        ViewBag.Name = name;
        return View();
    }
}

View

Source cshtml page

@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Index</title>
</head>
<body>
    @using (Html.BeginForm("Greetings", "Home", FormMethod.Post))
    {
        <table cellpadding="2" cellspacing="0" border="0">
            <tr>
                <td>Name:</td>
                <td>
                    @Html.TextBox("Name")
                </td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Submit"/></td>
            </tr>
        </table>
    }
</body>
</html>

Destination cshtml page

@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <title>Greetings</title>
</head>
<body>
     <span>Name: </span>@ViewBag.Name
</body>
</html>