I am new to work with MVC and I have confusion that how to retrieve the data of an item selected from the drop down list to the textbox. There are six items in the list and for each item there has different descriptions. This is my model class
public partial class Service { public int Id { get; set; } public string ItemName { get; set; } public string Description { get; set; } }
In this ItemName are the items in the dropdown list, and description is the data for each items in the dropdown, these values are stored in the table.
controller page
public async Task
if (id == null)
{return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
Service service = await db.Services.FindAsync(id);
if (service == null)
{return HttpNotFound();
}
return View(service);
}// POST: Services/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.[HttpPost]
[ValidateAntiForgeryToken]
public async Task
{if (ModelState.IsValid){db.Entry(service).State = EntityState.Modified;await db.SaveChangesAsync();return RedirectToAction("Index");
}
return View(service);
}
Here how can I bind the id of the drop down items in the table to the edit action method??
view page
@Html.DropDownListFor(model => model.ItemName, new SelectList(new[] { "Core Banking", "ATM", "RTGS/NEFT", "IFSC Code", "Money Transfer", "Locker Facility", "Mobile Banking (MAMBA)" }), "Select") @Html.ValidationMessageFor(model => model.ItemName, "", new { @class = "text-danger" }) div>div> div> here i want to get the data of the item to the @Html.TextArea(). Is that possible to retrieve the data when a button is pressed?? I have created a GO button on the view page and select the item from drop down list. Then how can I get the value from the table for the item that i have selected from the drop down list ?? How can I solve this issue ?? Know the answer? Post it. Somebody with the same question will find it here. Answer a question in the forums and earn +20 SHARP for every answer.1 Answer
Top experts
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answersFull leaderboard →
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Joginder BangerRank #360 · 7K reputationPosted Feb 10, 2017, 2:52 AM EST