Passing Data From Controller To View With ViewBag MVC

Passing Data From Controller To View With ViewBag MVC

 

public IActionResult Index()
        {
           ViewBag.FirstName = "Ram";
           ViewBag.MiddleName = "Kumar";
           ViewBag.LastName = "Singh";
              
           return View();
        }

 

<div class="form-group">
                        <label>First Name</label>
                        <input type="text" class="form-control" value="@ViewBag.FirstName" id="txt_firstname" name="txt_firstname" />
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>Middle Name</label>
                        <input type="text" class="form-control" value="@ViewBag.MiddleName" id="txt_middlename" name="txt_middlename" />
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                        <label>Last Name</label>
                        <input type="text" class="form-control" value="@ViewBag.LastName" id="txt_lastname" name="txt_lastname" />
                    </div>
                </div>

2021-10-03