I have following controller class methods for get and post actions of updating a person record in my MVC application using a WCF service. There I'm using a combobox to select the ID. Here is my controller class methods for getting the person details.
public ActionResult updatePerson()
{
Service1Client SCOBJ = new Service1Client();
List<Person> PeLi = SCOBJ.GetPersons().ToList();
ViewBag.List = PeLi.Select(x => new SelectListItem
{
Value = (Convert.ToString(x.Id)),
Text = x.FName + " " + x.LName
});
return View();
}
[HttpPost]
public ActionResult updatePerson(Person personobj)
{
Service1Client SCOBJ = new Service1Client();
SCOBJ.UpdatePerson(personobj);
List<Person> PeLi = SCOBJ.GetPersons().ToList();
ViewBag.List = PeLi.Select(x => new SelectListItem
{
Value = (Convert.ToString(x.Id)),
Text = x.FName + " " + x.LName
});
return View();
}
This is my view.
<form method="post" action="@Url.Action("updatePerson")">
ID:@Html.DropDownList("Id", new SelectList(ViewBag.List, "Value", "Text"))
@*<input type="text" name="Id" />*@
<br />
First Name: <input type="text" name="FName" />
<br />
Middle Name: <input type="text" name="MName" />
<br />
Last Name: <input type="text" name="LName" />
<br />
Date of Birth:<input type="date" id="start" name="DOB" value="2018-07-22" min="1900-01-01" max="2000-12-31" />
<br />
NIC:<input type="text" name="NIC" />
<br />
Address:<input type="text" name="Adddress" />
<br />
<input type="submit" value="Insert" />
</form>
I want to achieve loading details to First Name Middle Name Last Name Address and NIC text fields and DOB date time input field when I change the selected value of the ID. In other word I want to load detail record to all field when i select an ID from select list for ID. How can I achieve this?