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. Sign in to answer this question It is the same account you read, post and publish with — and you will come straight back to this page.1 Reply
Joginder BangerPosted Feb 10, 2017, 7:52 AM